Android ListView with onClick items

前端 未结 9 1602
梦如初夏
梦如初夏 2020-11-27 03:33

I\'m a new programmer and new in Android. I\'m using this example http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ and it works great.

9条回答
  •  眼角桃花
    2020-11-27 03:51

    listview.setOnItemClickListener(new OnItemClickListener(){
    
    //setting onclick to items in the listview.
    
    @Override
    public void onItemClick(AdapterViewadapter,View v, int position){
    Intent intent;
    switch(position){
    
    // case 0 is the first item in the listView.
    
      case 0:
        intent = new Intent(Activity.this,firstActivity.class);
        break;
    //case 1 is the second item in the listView.
    
      case 1:
        intent = new Intent(Activity.this,secondActivity.class);
        break;
     case 2:
        intent = new Intent(Activity.this,thirdActivity.class);
        break;
    //add more if you have more items in listView
    startActivity(intent);
    }
    
    });
    

提交回复
热议问题