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

ListView lst = (ListView) findViewById(R.id.list);
        lst.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(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);

Object obj = 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);

    final BaseAdapter adapter = new PreviewAdapter(this, name, age);

    confirm.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            View view = null;

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

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

                Textview et = (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?"