How do I implement expandablelistview with child search filter?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have made an expandablelistview with child activities, and now I want to implement a searchView with search filter for the children, but I dont know how to do it. I have searched on the internet for a solution but them i tried didn´t work.
I want to be able to search filter after the child such as "Super" and when i click on "Super" it opens the activity.
Can someone help me with this?
Heres my code:
MainActivity:
public class MainActivity extends AppCompatActivity {
ExpandableListView expandableListView;
List<String> langs;
Map<String, List<String>> topics;
ExpandableListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
fillData();
listAdapter = new MyExListAdapter(this,langs,topics);
expandableListView.setAdapter(listAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition)
{
case 0: // Dette er groupPosition (altså Java)
switch (childPosition)
{
case 0: // Dette er childPosition
Super();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Encapsulation();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Methods();
break;
case 3:
//do something
break;
}
break; //Husk break her for at undgå du åbner for begge parents første child
case 1: // Dette er groupPosition (altså C)
switch (childPosition)
{
case 0:
Procedure();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Pointer();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Array();
break;
case 3:
//do something
break;
}
break;
}
return false;
}
// Hovedgruppe Java
private void Super() {
Intent MyIntent = new Intent(MainActivity.this, Super.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Encapsulation() {
Intent MyIntent = new Intent(MainActivity.this, Encapsulation.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Methods() {
Intent MyIntent = new Intent(MainActivity.this, Methods.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
// Hovedgruppe C
private void Procedure() {
Intent MyIntent = new Intent(MainActivity.this, Procedure.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Pointer() {
Intent MyIntent = new Intent(MainActivity.this, Pointer.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Array() {
Intent MyIntent = new Intent(MainActivity.this, Array.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
});
}
public void fillData()
{
langs = new ArrayList<>();
topics = new HashMap<>();
langs.add("Java");
langs.add("C");
List<String> java = new ArrayList<>();
List<String> C = new ArrayList<>();
// Hovedgruppe java
java.add("Super");
java.add("Encapsulation");
java.add("Methods");
// Hovedgruppe C
C.add("Procedure");
C.add("Pointers");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
topics.put(langs.get(0),java);
topics.put(langs.get(1),C);
}
}
MyExListAdapter:
public class MyExListAdapter extends BaseExpandableListAdapter
{
Context context;
List<String> langs;
Map<String, List<String>> topics;
public MyExListAdapter(Context context, List<String> langs, Map<String, List<String>> topics) {
this.context = context;
this.langs = langs;
this.topics = topics;
}
@Override
public int getGroupCount() {
return langs.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return topics.get(langs.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return langs.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return topics.get(langs.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String lang = (String) getGroup(groupPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_parent,null);
}
TextView txtParent = (TextView) convertView.findViewById(R.id.txtParent);
txtParent.setText(lang);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String topic = (String) getChild(groupPosition,childPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_child,null);
}
TextView txtChild = (TextView) convertView.findViewById(R.id.txtChild);
txtChild.setText(topic);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/expandableListView"
android:groupIndicator="@null"
android:cacheColorHint="#00000000"
android:listSelector="@android:color/transparent"
/>
</RelativeLayout>
add a comment |
I have made an expandablelistview with child activities, and now I want to implement a searchView with search filter for the children, but I dont know how to do it. I have searched on the internet for a solution but them i tried didn´t work.
I want to be able to search filter after the child such as "Super" and when i click on "Super" it opens the activity.
Can someone help me with this?
Heres my code:
MainActivity:
public class MainActivity extends AppCompatActivity {
ExpandableListView expandableListView;
List<String> langs;
Map<String, List<String>> topics;
ExpandableListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
fillData();
listAdapter = new MyExListAdapter(this,langs,topics);
expandableListView.setAdapter(listAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition)
{
case 0: // Dette er groupPosition (altså Java)
switch (childPosition)
{
case 0: // Dette er childPosition
Super();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Encapsulation();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Methods();
break;
case 3:
//do something
break;
}
break; //Husk break her for at undgå du åbner for begge parents første child
case 1: // Dette er groupPosition (altså C)
switch (childPosition)
{
case 0:
Procedure();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Pointer();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Array();
break;
case 3:
//do something
break;
}
break;
}
return false;
}
// Hovedgruppe Java
private void Super() {
Intent MyIntent = new Intent(MainActivity.this, Super.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Encapsulation() {
Intent MyIntent = new Intent(MainActivity.this, Encapsulation.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Methods() {
Intent MyIntent = new Intent(MainActivity.this, Methods.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
// Hovedgruppe C
private void Procedure() {
Intent MyIntent = new Intent(MainActivity.this, Procedure.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Pointer() {
Intent MyIntent = new Intent(MainActivity.this, Pointer.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Array() {
Intent MyIntent = new Intent(MainActivity.this, Array.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
});
}
public void fillData()
{
langs = new ArrayList<>();
topics = new HashMap<>();
langs.add("Java");
langs.add("C");
List<String> java = new ArrayList<>();
List<String> C = new ArrayList<>();
// Hovedgruppe java
java.add("Super");
java.add("Encapsulation");
java.add("Methods");
// Hovedgruppe C
C.add("Procedure");
C.add("Pointers");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
topics.put(langs.get(0),java);
topics.put(langs.get(1),C);
}
}
MyExListAdapter:
public class MyExListAdapter extends BaseExpandableListAdapter
{
Context context;
List<String> langs;
Map<String, List<String>> topics;
public MyExListAdapter(Context context, List<String> langs, Map<String, List<String>> topics) {
this.context = context;
this.langs = langs;
this.topics = topics;
}
@Override
public int getGroupCount() {
return langs.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return topics.get(langs.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return langs.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return topics.get(langs.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String lang = (String) getGroup(groupPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_parent,null);
}
TextView txtParent = (TextView) convertView.findViewById(R.id.txtParent);
txtParent.setText(lang);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String topic = (String) getChild(groupPosition,childPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_child,null);
}
TextView txtChild = (TextView) convertView.findViewById(R.id.txtChild);
txtChild.setText(topic);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/expandableListView"
android:groupIndicator="@null"
android:cacheColorHint="#00000000"
android:listSelector="@android:color/transparent"
/>
</RelativeLayout>
add a comment |
I have made an expandablelistview with child activities, and now I want to implement a searchView with search filter for the children, but I dont know how to do it. I have searched on the internet for a solution but them i tried didn´t work.
I want to be able to search filter after the child such as "Super" and when i click on "Super" it opens the activity.
Can someone help me with this?
Heres my code:
MainActivity:
public class MainActivity extends AppCompatActivity {
ExpandableListView expandableListView;
List<String> langs;
Map<String, List<String>> topics;
ExpandableListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
fillData();
listAdapter = new MyExListAdapter(this,langs,topics);
expandableListView.setAdapter(listAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition)
{
case 0: // Dette er groupPosition (altså Java)
switch (childPosition)
{
case 0: // Dette er childPosition
Super();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Encapsulation();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Methods();
break;
case 3:
//do something
break;
}
break; //Husk break her for at undgå du åbner for begge parents første child
case 1: // Dette er groupPosition (altså C)
switch (childPosition)
{
case 0:
Procedure();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Pointer();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Array();
break;
case 3:
//do something
break;
}
break;
}
return false;
}
// Hovedgruppe Java
private void Super() {
Intent MyIntent = new Intent(MainActivity.this, Super.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Encapsulation() {
Intent MyIntent = new Intent(MainActivity.this, Encapsulation.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Methods() {
Intent MyIntent = new Intent(MainActivity.this, Methods.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
// Hovedgruppe C
private void Procedure() {
Intent MyIntent = new Intent(MainActivity.this, Procedure.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Pointer() {
Intent MyIntent = new Intent(MainActivity.this, Pointer.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Array() {
Intent MyIntent = new Intent(MainActivity.this, Array.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
});
}
public void fillData()
{
langs = new ArrayList<>();
topics = new HashMap<>();
langs.add("Java");
langs.add("C");
List<String> java = new ArrayList<>();
List<String> C = new ArrayList<>();
// Hovedgruppe java
java.add("Super");
java.add("Encapsulation");
java.add("Methods");
// Hovedgruppe C
C.add("Procedure");
C.add("Pointers");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
topics.put(langs.get(0),java);
topics.put(langs.get(1),C);
}
}
MyExListAdapter:
public class MyExListAdapter extends BaseExpandableListAdapter
{
Context context;
List<String> langs;
Map<String, List<String>> topics;
public MyExListAdapter(Context context, List<String> langs, Map<String, List<String>> topics) {
this.context = context;
this.langs = langs;
this.topics = topics;
}
@Override
public int getGroupCount() {
return langs.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return topics.get(langs.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return langs.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return topics.get(langs.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String lang = (String) getGroup(groupPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_parent,null);
}
TextView txtParent = (TextView) convertView.findViewById(R.id.txtParent);
txtParent.setText(lang);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String topic = (String) getChild(groupPosition,childPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_child,null);
}
TextView txtChild = (TextView) convertView.findViewById(R.id.txtChild);
txtChild.setText(topic);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/expandableListView"
android:groupIndicator="@null"
android:cacheColorHint="#00000000"
android:listSelector="@android:color/transparent"
/>
</RelativeLayout>
I have made an expandablelistview with child activities, and now I want to implement a searchView with search filter for the children, but I dont know how to do it. I have searched on the internet for a solution but them i tried didn´t work.
I want to be able to search filter after the child such as "Super" and when i click on "Super" it opens the activity.
Can someone help me with this?
Heres my code:
MainActivity:
public class MainActivity extends AppCompatActivity {
ExpandableListView expandableListView;
List<String> langs;
Map<String, List<String>> topics;
ExpandableListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
fillData();
listAdapter = new MyExListAdapter(this,langs,topics);
expandableListView.setAdapter(listAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition)
{
case 0: // Dette er groupPosition (altså Java)
switch (childPosition)
{
case 0: // Dette er childPosition
Super();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Encapsulation();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Methods();
break;
case 3:
//do something
break;
}
break; //Husk break her for at undgå du åbner for begge parents første child
case 1: // Dette er groupPosition (altså C)
switch (childPosition)
{
case 0:
Procedure();
break;
case 1:
//do something
break;
}
switch (childPosition)
{
case 1:
Pointer();
break;
case 2:
//do something
break;
}
switch (childPosition)
{
case 2:
Array();
break;
case 3:
//do something
break;
}
break;
}
return false;
}
// Hovedgruppe Java
private void Super() {
Intent MyIntent = new Intent(MainActivity.this, Super.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Encapsulation() {
Intent MyIntent = new Intent(MainActivity.this, Encapsulation.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Methods() {
Intent MyIntent = new Intent(MainActivity.this, Methods.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
// Hovedgruppe C
private void Procedure() {
Intent MyIntent = new Intent(MainActivity.this, Procedure.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Pointer() {
Intent MyIntent = new Intent(MainActivity.this, Pointer.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Bruges for at undgå den åbner to af samme activities (flag activity clear top)
startActivity(MyIntent);
}
private void Array() {
Intent MyIntent = new Intent(MainActivity.this, Array.class);
MyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(MyIntent);
}
});
}
public void fillData()
{
langs = new ArrayList<>();
topics = new HashMap<>();
langs.add("Java");
langs.add("C");
List<String> java = new ArrayList<>();
List<String> C = new ArrayList<>();
// Hovedgruppe java
java.add("Super");
java.add("Encapsulation");
java.add("Methods");
// Hovedgruppe C
C.add("Procedure");
C.add("Pointers");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
C.add("Array");
topics.put(langs.get(0),java);
topics.put(langs.get(1),C);
}
}
MyExListAdapter:
public class MyExListAdapter extends BaseExpandableListAdapter
{
Context context;
List<String> langs;
Map<String, List<String>> topics;
public MyExListAdapter(Context context, List<String> langs, Map<String, List<String>> topics) {
this.context = context;
this.langs = langs;
this.topics = topics;
}
@Override
public int getGroupCount() {
return langs.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return topics.get(langs.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return langs.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return topics.get(langs.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String lang = (String) getGroup(groupPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_parent,null);
}
TextView txtParent = (TextView) convertView.findViewById(R.id.txtParent);
txtParent.setText(lang);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String topic = (String) getChild(groupPosition,childPosition);
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_child,null);
}
TextView txtChild = (TextView) convertView.findViewById(R.id.txtChild);
txtChild.setText(topic);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/expandableListView"
android:groupIndicator="@null"
android:cacheColorHint="#00000000"
android:listSelector="@android:color/transparent"
/>
</RelativeLayout>
edited Nov 26 '18 at 10:34
Simon
asked Nov 21 '18 at 20:59
SimonSimon
13
13
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420402%2fhow-do-i-implement-expandablelistview-with-child-search-filter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420402%2fhow-do-i-implement-expandablelistview-with-child-search-filter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown