Skip to content Skip to sidebar Skip to footer

How To Get Listview Position?

I have problem in Listview onListItemClick() method. I am not getting the position of the list. Here is my code Pls help me coverletterselection.xml

Solution 1:

i think You forget to setOnItemClickListener

ListViewlst= (ListView) findViewById(R.id.list);
        lst.setOnItemClickListener(newOnItemClickListener() {

            @OverridepublicvoidonItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {
                // TODO Auto-generated method stub
                Log.i("OnClick", "position = " + position);
            }
        });

add this line in your code...

Solution 2:

Clearly seems from your code, u forgot to mention list.setOnItemClickListener(this);

Objectobj= parent.getItemAtPosition(position);

in case, you want to get object in onItemClick

Solution 3:

in the onItemClick function,the third parameter is the position of item which you click.

Solution 4:

you forgot the setOnItemClickListener()

in order to listen the event on your List :)

and one more thing , i can't see in your code where you get your ListView ( findViewById ).

Look your code i've edited it to fixe the problem

Hope it works :)

Solution 5:

In a Activity Button onclick to get all listview item.

Listview lv = (ListView) findViewById(R.id.previewlist);

finalBaseAdapteradapter=newPreviewAdapter(this, name, age);

    confirm.setOnClickListener(newOnClickListener() {

        @OverridepublicvoidonClick(View v) {

            Viewview=null;

            String value;
            for (inti=0; i < adapter.getCount(); i++) {

                view = adapter.getView(i, view, lv);

                Textviewet= (TextView) view.findViewById(R.id.passfare);

                value=et.getText().toString();

                 Toast.makeText(getApplicationContext(), value,Toast.LENGTH_SHORT).show();

            }

        }
    });

Post a Comment for "How To Get Listview Position?"