我有一个列表和一个包含子项的列表项。但我需要第二个listitem和第二个listitem的子项。那么如何在项目中添加第二,第三......项目和子项目? *抱歉我的英语很差。
package com.deneeme.deneme;
import java.util.ArrayList;
import com.deneeme.deneme.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.Menu;
import android.widget.ExpandableListView;
import android.widget.TextView;
public class MainActivity extends Activity {
// more efficient than HashMap for mapping integers to objects
SparseArray<Group> groups = new SparseArray<Group>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData();
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,
groups);
listView.setAdapter(adapter);
}
public void createData() {
for (int a = 0; a < 1; a++) {
Group group = new Group("Elma");
for (int b = 0; b < 1; b++) {
group.children.add("E1");
group.children.add("E2");
group.children.add("E3");
}
groups.append(a, group);
}
}
}