这就是我定义的listview数组。
private String lv_arr[] = {"number1", "number2", "number3", "number4"};
如何更改要与number1.java
,number2.java
,number3.java
和number4.java
关联的内容?
[被修改]
链接:http://pastebin.com/BH8N4dKb
将帖子 http://pastebin.com/GjrBj2m5
现在我没有任何错误,但它仍然没有其他任何错误。
答案 0 :(得分:2)
像这样使用。
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, Categories));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
switch (position){
case 0: Intent animalsGridViewIntent = new Intent(ListOfAppGallery.this,N1.class);
ListOfAppGallery.this.startActivity(animalsGridViewIntent);
break;
case 1: Intent calenderGridViewIntent = new Intent(ListOfAppGallery.this,N2.class);
ListOfAppGallery.this.startActivity(calenderGridViewIntent);
break;
case 2: Intent carsGridViewIntent = new Intent(ListOfAppGallery.this,N3.class);
ListOfAppGallery.this.startActivity(carsGridViewIntent);
break;
case 3: Intent creativeGridViewIntent = new Intent(ListOfAppGallery.this,N4.class);
ListOfAppGallery.this.startActivity(creativeGridViewIntent);
break;
}
}
});
}
答案 1 :(得分:0)
抓住您的列表视图:
listView.setOnItemOnClickListener()
并检查案例检查以开始新活动:
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,long id) {
Intent intent;
switch (position) {
case 1:
intent=new Intent(getApplicationContext(),NumberOne.java)
getApplicationContext().startActivity(intent);
break;
case 2:
intent=new Intent(getApplicationContext(),NumberTwo.java);
getApplicationContext().startActivity(intent);
break;
case 3:
intent=new Intent(getApplicationContext(),NumberThree.java);
getApplicationContext().startActivity(intent);
break;
case 4:
intent=new Intent(getApplicationContext(),NumberFour.java);
getApplicationContext().startActivity(intent);
break;
default:
break;
}
}
});