Mr.Radar Mr.Radar - 22 days ago 7
Android Question

Android ExpandableList with static items/without adapter

In my app, there is an Activity which contains a lot of Views (editText-fields,...). Because of that the screen is too small to fit all the views. Therefore I want to use an ExpandableList which contains all the views semantically grouped (as Layouts) to list items.

Is there an easy way to get this done? Implementing an Adapter seems to be a bit complicated, regarding that the list should only contain "static" views.

Something like this would be nice:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExpandableListView lv = (ExpandableListView) findViewById(R.id.explist);
lv.addItem(findViewById(R.id.linearlayoutitemone);
lv.addItem(findViewById(R.id.linearlayoutitemtwo);
EditText et = (EditText) lv.getItem(1).findViewById(R.id.etBirthdate);
et.setText("01.01.1970");
(....)
}

Answer

I've written an own adapter extending BaseExpandableListAdapter. In the adapter i keep instances of the layouts to display as class variables - not the best solution regarding performance, but a convenient solution. As there is only a fixed short number of items to display, the performance issue won't bother much.

Comments