views:

24

answers:

1

the problem is that i have two listView but one itemClick method, if i put a switch, the position on one list is the same than the other list... And by example if i want to open a popup on an item in one list, the item in the same position in the other list gonna do the same thing, and i really don't want, can you help me? Thanks

there is the code :

public void onItemClick(AdapterView parent, View v, int position, long id) { Object str = parent.getId(); if(str.equals(adapter_todo)){ switch(position){ case 0 : new AlertDialog.Builder(this).setTitle("test").setMessage("blah blah").setNeutralButton("close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        }).show();
        case 1 :
        case 2 :
        case 3 :
        case 4 :
        case 5 :
        case 6 :
        case 7 :
        case 8 :
        case 9 :
        case 10 :
        }


    }
    else if(str.equals(adapter_not_todo)){
        switch(position){
        case 0 : new AlertDialog.Builder(this).setTitle("test 2").setMessage("blah blah blah").setNeutralButton("close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        }).show();
        case 1 :
        case 2 :
        case 3 :
        case 4 :
        case 5 :
        case 6 :
        case 7 :
        case 8 :
        case 9 :
        case 10 :
        }
    }
+1  A: 

In onItemClick, call parent.getId() to tell which list view was clicked.

Thorstenvv
how can i use it ? It's like : if(parent.getId().equals(v)) or something like this ?
Tsunaze
if ( parent.getId() == R.id.ListView01){ ... } else if (parent.getID() == R.id.ListView02){ ... } // use the resource IDs as defined in the layout file
Thorstenvv
Thank you ! =D !
Tsunaze
You're welcome. Please accept the answer if you like it.
Thorstenvv