我跟着一個教程,並有一個可擴展的ListView,並希望鏈接到一個新的活動的孩子 - 我將如何去做到這一點?我是新來的Android所以任何幫助,將不勝感激:)ListView的孩子到新的意圖
createGroupList();
createCollection();
expListView = (ExpandableListView) findViewById(R.id.search_list);
final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(
this, groupList, advSearchOption);
expListView.setAdapter(expListAdapter);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
final String selected = (String) expListAdapter.getChild(
groupPosition, childPosition);
Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG)
.show();
return true;
}
});
private void createGroupList() {
groupList = new ArrayList<String>();
groupList.add("Advanced Search");
}
private void createCollection() {
// preparing laptops collection(child)
String[] searches = { "Height", "Weight",
"Hair Colour" };
advSearchOption = new LinkedHashMap<String, List<String>>();
for (String advSearch : groupList) {
if (advSearch.equals("Advanced Search")) {
loadChild(searches);
}
advSearchOption.put(advSearch, childList);
}
}
private void loadChild(String[] searchOptions) {
childList = new ArrayList<String>();
for (String model : searchOptions)
childList.add(model);
}
嗨,感謝您的反饋,我將如何指定我的孩子列表中的哪個項目將鏈接到新的活動? – rory 2015-01-21 01:10:05
@rory你有一些數據綁定到你的子項目,你可以通過getChild(int groupPosition,int childPosition)獲取數據,並將一些數據放入intent – jobcrazy 2015-01-21 01:21:36
Hi @jobcrazy,我想要高度鏈接到一個新的活動 String []搜索= {「身高」,「體重」, 「頭髮顏色」}; – rory 2015-01-21 01:28:07