I need to make an ExpandableListView
with 3 TextView
s in parent and child lists. I have parentlist
and childlist
with 3 TextView
s in each line. So what should I do next?
ArrayList<Contact> list = new ArrayList<>(); //main_equip
list.add(new Contact("Surdialx", "Status","Available Works"));
list.add(new Contact("Surdial", "Status","Available Works"));
list.add(new Contact("Surdialx", "Status","Available Works"));
list.add(new Contact("Surdial", "Status","Available Works"));
list.add(new Contact("Surdialx", "Status","Available Works"));
list.add(new Contact("Surdial", "Status","Available Works"));
ArrayList<Contact1> childlist = new ArrayList<>(); //eq_works
childlist.add(new Contact1("Work №1", "Status", "Priority"));
childlist.add(new Contact1("Work №2", "Status","Priority"));
childlist.add(new Contact1("Work №3", "Status","Priority"));
To create Expandable Recyclerview try this way
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
recyclerview.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
List<ExpandableListAdapter.Item> data = new ArrayList<>();
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.HEADER, "Fruits"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Apple"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Orange"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Banana"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.HEADER, "Cars"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Audi"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Aston Martin"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "BMW"));
data.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Cadillac"));
ExpandableListAdapter.Item places = new ExpandableListAdapter.Item(ExpandableListAdapter.HEADER, "Places");
places.invisibleChildren = new ArrayList<>();
places.invisibleChildren.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Kerala"));
places.invisibleChildren.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Tamil Nadu"));
places.invisibleChildren.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Karnataka"));
places.invisibleChildren.add(new ExpandableListAdapter.Item(ExpandableListAdapter.CHILD, "Maharashtra"));
data.add(places);
recyclerview.setAdapter(new ExpandableListAdapter(data));
}
}