你怎么做到这一点?

时间:2011-10-14 06:49:52

标签: android listview

这就是我定义的listview数组。

private String lv_arr[] = {"number1", "number2", "number3", "number4"};

如何更改要与number1.javanumber2.javanumber3.javanumber4.java关联的内容?

[被修改]

链接:http://pastebin.com/BH8N4dKb

将帖子 http://pastebin.com/GjrBj2m5

现在我没有任何错误,但它仍然没有其他任何错误。

2 个答案:

答案 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;
                    }
                }

});