How to make more than one listview respond for different onItemClickListener?

前端 未结 1 675
慢半拍i
慢半拍i 2021-01-06 16:29

I\'m using 4list views with class extending Activity. I have to perform different list item click function. Can i use the following method code for it? So how to set a singl

相关标签:
1条回答
  • 2021-01-06 16:58

    Set different adapters for different list views. I take two list view for example. So take two adapter for these two. And setOnItemClick(context) will be like as below..

     public void onItemClick(AdapterView<?> adv, View v, int arg2, long arg3) {
        // TODO Auto-generated method stub
    
        switch(adv.getId()) {
            case R.id.ListView1:
                Toast.makeText(this, "list1", Toast.LENGTH_LONG).show();
                break;
            case R.id.ListView2:
                Toast.makeText(this, "list2", Toast.LENGTH_LONG).show();
                break;
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题