我正在expandablelistview上打开标题,然后子标题。但是,当我单击副标题时,它应该打开新活动。
请在这里帮助我,而不是单击显示子项的吐司。
private OnChildClickListener myListItemClicked = new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//get the group header
HeaderInfo headerInfo = SectionList.get(groupPosition);
//get the child info
DetailInfo detailInfo = headerInfo.getProductList().get(childPosition);
//display it or do something with it
Toast.makeText(getBaseContext(), "Clicked on Detail " + headerInfo.getName()
+ "/" + detailInfo.getName(), Toast.LENGTH_LONG).show();
return false;
}
};
答案 0 :(得分:0)
将ThisActivity替换为您当前的活动,并将YourNewActivity替换为您要进行的新活动
private OnChildClickListener myListItemClicked = new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//get the group header
HeaderInfo headerInfo = SectionList.get(groupPosition);
//get the child info
DetailInfo detailInfo = headerInfo.getProductList().get(childPosition);
//display it or do something with it
Toast.makeText(getBaseContext(), "Clicked on Detail " + headerInfo.getName()
+ "/" + detailInfo.getName(), Toast.LENGTH_LONG).show();
switch(childPosition) {
case 0:
Intent intent = new Intent(ThisActivity.this, YourNewActivity0.class);
break;
case 1:
Intent intent = new Intent(ThisActivity.this, YourNewActivity1.class);
break;
case 2:
Intent intent = new Intent(ThisActivity.this, YourNewActivity2.class);
break;
}
startActivity(intent);
return false;
}
};
答案 1 :(得分:0)
感谢@Angus Tay; 您的回覆让我知道 我找到了下面给出的答案,它对我有用...
switch(groupPosition) {
case 0:
switch (childPosition) {
case 0:
Intent c1= new Intent(MainActivity.this,YourNewActivity0.class);
startActivity(c1);
break;
case 1:
Intent d2= new Intent(MainActivity.this,YourNewActivity1.class);
startActivity(d2);
break;
case 2:
Intent d3= new Intent(MainActivity.this,YourNewActivity2.class);
startActivity(d3);
break;
}
break;
case 1:
switch (childPosition) {
case 0:
Intent d1= new Intent(MainActivity.this,YourNewActivity0.class);
startActivity(d1);
break;
case 1:
Intent d2= new Intent(MainActivity.this,YourNewActivity1.class);
startActivity(d2);
break;
}
break;
case 2:
switch (childPosition) {
case 0:
Intent a1= new Intent(MainActivity.this,YourNewActivity0.class);
startActivity(a1);
break;
case 1:
Intent a2= new Intent(MainActivity.this,YourNewActivity1.class);
startActivity(a2);
break;
}
}
return false;
}
};