0
在下面的代码我加载一个ArrayList数据一个接一个。快速ArrayList加载
此ArrayList用于ExpandableListView。所以它包含组和孩子。
每个组都有一个名称和一个描述。
每个孩子都有一个名字。
有些群体没有childern。
public class CategoriesExpandableList extends Activity implements OnChildClickListener,
OnGroupClickListener, OnGroupExpandListener, OnGroupCollapseListener {
private static Context mContext;
private ExpandListAdapter ExpAdapter=null;
private ArrayList<ExpandListGroup> ExpListItems;
ArrayList<ExpandListGroup> list=null;
private ExpandableListView ExpandList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.categoriesexpandable);
ExpandList = (ExpandableListView) findViewById(R.id.ExpList);
ExpListItems = SetStandardGroups();
ExpAdapter = new ExpandListAdapter(CategoriesExpandableList.this, ExpListItems);
ExpandList.setAdapter(ExpAdapter);
ExpandList.setOnGroupClickListener(this);
ExpandList.setOnChildClickListener(this);
mContext=this;
}
public ArrayList<ExpandListGroup> SetStandardGroups() {
ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru0 = new ExpandListGroup();
gru0.setName("My Favorites");
gru0.setDescription("My favourite points of interest");
gru0.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru1 = new ExpandListGroup();
gru1.setName("Essentials");
gru1.setDescription("Very essential points of interest");
gru1.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru2 = new ExpandListGroup();
gru2.setName("Sights");
gru2.setDescription("Beautiful sights you have to visit");
gru2.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru3 = new ExpandListGroup();
gru3.setName("Beaches");
gru3.setDescription("Beaches near Agios Nikolaos");
ExpandListChild ch3_0 = new ExpandListChild();
ch3_0.setName("In town");
ch3_0.setTag(null);
list2.add(ch3_0);
ExpandListChild ch3_1 = new ExpandListChild();
ch3_1.setName("Outside town");
ch3_1.setTag(null);
list2.add(ch3_1);
gru3.setItems(list2);
list2 = new ArrayList<ExpandListChild>();
list.add(gru0);
list.add(gru1);
list.add(gru2);
list.add(gru3);
return list;
}
}
我想知道是否有在ArrayList中加载这些数据的快捷方式。例如,通过调用像这样的方法:
addPoint(String groupname, String groupdescription, String child01)
addPoint("Banks", "Banks and ATMs", "Only banks")
addPoint("Banks", "Banks and ATMs", "Only ATMs")
// Here i have only a group and no children...
addPoint("Sights", "Beautiful sights to visit", "")