处理2个活动清单?

时间:2014-01-29 05:40:28

标签: android list

我觉得答案是如此明显但我没注意到,当我在一个活动上有2个列表时如何控制onListItemClick void?所以,如果我想为2组不同的信息设置2个不同的列表

2 个答案:

答案 0 :(得分:3)

您应该/可以对同一活动中的不同onItemClick使用单ListView方法:

  public void onItemClick(AdapterView<?> a, View v, int position, long id) {}
只有一次。然后,您可以执行类似v.getId() v View的内容,它将为您提供Listview的ID,根据该ID,您可以处理多个项目点击监听器ListView

v.getId();

并处理项目的两个`ListView的点击监听器,如下所示:

public void onItemClick(AdapterView<?> a, View v, int position, long id) {

        if( v.getId() == R.id.listView1 )
        {
           //Your logic for the first listview
        }
        else if( v.getId() == R.id.listView2 )
        {
           //Your logic for the second listview               
         }

        }
 }

答案 1 :(得分:0)

you can use two defferent method for listview ::->


 tasks_list.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View v, int position,
                        long id) {
                    // TODO Auto-generated method stub
                    mapp=true;
                    Intent i = new Intent(Home_Activity.this,AddTask_Activity.class);
                    i.putExtra(DBAdapter.KEY_ROW_ID, id);
                    Log.d("IDD", ""+id);

                    startActivity(i);

                }
            });
            tasks_list1.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View v, int position,
                        long id) {
                    // TODO Auto-generated method stub
                    mapp=true;
                    Intent i = new Intent(Home_Activity.this,AddTask_Activity.class);
                    i.putExtra(DBAdapter.KEY_ROW_ID, id);
                    Log.d("IDD1", ""+id);
                    startActivity(i);

                }
            });