Ich denke der ExpandableListView ist in der Tat das richtige für dich. Ich habe diesen auch schon öfters benutzt, allerdings eher zu meiner Anfangszeit, weswegen er nicht so wirklich ausgereift und sauber programmiert ist, aber ich stell dir mal ein bisschen Beispiel-Code bereit.
Als erstes wie ich den ExpandableListView initialisiere, und dann mein ExpandableListViewAdapter, wobei ich hier z.B. meine ChildViews mit WebViews gefüllt habe und die HTML Seiten im assets Ordner liegen. Du kannst aber auch alles mögliche rein setzen. Dieser Quellcode benötgt definitv noch eine Überarbeitung, aber er funktioniert erstmal so :-)
[code]
private void initializeExpandableListView() {
ExpandableListView lv = view.getExpandableListView();
SimpleExpandableListAdapter adapter = new ExpandableListViewAdapter(
view,
createGroupList(view.getResources().getStringArray(R.array.infoArray), "infoMenuPoint"),
R.layout.expandable_list_adapter_group,
new String[] { "infoMenuPoint"},
new int[] { R.id.GroupName },
createChildList(view.getResources().getStringArray(R.array.infoTextArray), "infoText"),
R.layout.expandable_list_adapter_child,
new String[] { "infoText"},
new int[] { R.id.recommendWebView }
);
lv.setAdapter(adapter);
view.setListView(lv);
}
private List<HashMap<String, String>> createGroupList(Object array[], String key) {
ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
for( int i = 0 ; i < array.length ; ++i ) {
HashMap<String, String> m = new HashMap<String, String>();
m.put( key, array[i].toString() );
result.add(m);
}
return (List<HashMap<String, String>>)result;
}
private List<ArrayList<HashMap<String, Object>>> createChildList(Object array[], String key) {
ArrayList<ArrayList<HashMap<String, Object>>> result = new ArrayList<ArrayList<HashMap<String, Object>>>();
for( int i = 0 ; i < array.length ; ++i ) {
ArrayList<HashMap<String, Object>> secList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> child = new HashMap<String, Object>();
child.put( key, array[i] );
secList.add(child);
result.add(secList);
}
return result;
}
// Adapter
public class ExpandableListViewAdapter extends SimpleExpandableListAdapter {
private Context context;
private String[] childFrom;
public ExpandableListViewAdapter(Context context,
List<? extends Map<String, ?>> groupData, int groupLayout,
String[] groupFrom, int[] groupTo,
List<? extends List<? extends Map<String, ?>>> childData,
int childLayout, String[] childFrom, int[] childTo) {
super(context, groupData, groupLayout, groupFrom, groupTo, childData,
childLayout, childFrom, childTo);
this.context = context;
this.childFrom = childFrom;
}
@SuppressWarnings("unchecked")
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.HORIZONTAL);
WebView wv = new WebView(context);
wv.loadUrl((String)((Map<String, ?>)getChild(groupPosition, childPosition)).get(childFrom[0]));
ll.addView(wv);
TextView tv = new TextView(context);
ll.addView(tv);
return ll;
}
}
[/code]
//Edit: Wegen dem Code-Tag entschuldige ich mich, aber er scheint nicht zu funktionieren.
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.