我现在正在和他一起工作ExpandableListView
。如果条件在二维数组中,我需要帮助如何使用 if 语句。我已经编写了这段代码,但是当我点击每个孩子时,它总是会进入游戏活动。我想要的是当每个孩子都被点击时,新的活动(取决于什么孩子)将被打开。
我是 OOP 的新手。所以也许你可以帮助我。谢谢!
listView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if ( CHILDREN[0][0] == "Management") {
Intent intent = new Intent(Information.this, Games.class);
startActivity(intent);
}
else if ( CHILDREN[0][1] == "Accountant") {
Intent intent = new Intent(Information.this, Test.class);
startActivity(intent);
}
else if ( CHILDREN[0][2] == "Economy") {
Intent intent = new Intent(Information.this, Chat.class);
startActivity(intent);
}
else {
Intent intent = new Intent(Information.this, MainActivity.class);
startActivity(intent);
}
return true;
}
});
如果有帮助 - 这是字符串数组声明:
private String[][] CHILDREN = {
{ "Management", "Accountant", "Economy" },
{ "IAB", "Communication" , "Hospitality" },
{ "English", "Theology", "BK", "Elementary" },
{ "Machine", "Electrical", "Industrial" },
{ "Law" },
{ "Doctor" },
{ "Psychology" },
{ "Biology" },
};