Ich suche nach einem Weg, um Daten in eine Expandale List View zu laden, die Ausgabe möchte ich die der angehängten Bild ähneln here Um dies dynamisch zu tun, ist es besser zu sein von einem CSV lesen? Oder um eine DB zu erstellen? Außerdem möchte ich bei einem Unterpunkt drücken, dass eine ScrollView erscheint.Daten in eine ExpandableListView laden
Hier ist der Code so weit: Das Layout der Aktivität:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ExpandableListView
android:id= "@+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
The itemlayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/grp_child"
android:paddingLeft="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Und die subitem:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/row_name"
android:paddingLeft="50dp"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
In der Tätigkeit habe ich bisher einige Werte fest einprogrammiert, einige mit Tutorials Ich stieß auf:
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photographers);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row,
new String[] { "Group Item" },
new int[] { R.id.row_name },
createChildList(),
R.layout.child_row,
new String[] {"Sub Item"},
new int[] { R.id.grp_child}
);
setListAdapter(expListAdapter);
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 15 ; ++i) { // 15 groups........
HashMap m = new HashMap();
m.put("Group Item","Group Item " + i); // the key and it's value.
result.add(m);
}
return (List)result;
}
@SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 15 ; ++i) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for(int n = 0 ; n < 3 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "Sub Item " + n);
secList.add(child);
}
result.add(secList);
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group expanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
Ich frage mich, ob es eine gute Idee ist Speichern Sie die Daten, die ich anzeigen möchte, in separaten CSV-Dateien (eine speichert die Daten für die Elemente, eine für die Unterelemente. eine für die zusätzlichen Informationen in der ScrollView), ID-s für die Identifizierung und zum direkten Lesen von den CSVs mit dem OpenCSVReader?
würde ich irgendwelche Ratschläge zu schätzen wissen, Dank
Haben Sie die ExpandableListView erstellt? Wo sind die Daten, die Sie laden möchten? Können Sie uns Ihren Code zeigen? –
Habe es oben hinzugefügt, danke! – VyaraG