user2380151
user2380151

Reputation: 151

How to get the value of the selected item from listview

I want to retrieve all the data of the selected row from listview.

this is what I have tried so far.....

listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        Object listItem = listview.getItemAtPosition(arg2);
    }
});

now i don't know, how to get the elements from the Object.

Upvotes: 0

Views: 673

Answers (1)

Rakeeb Rajbhandari
Rakeeb Rajbhandari

Reputation: 5063

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            Object listItem = (Object)parent.getItemAtPosition(position);
}

Usually the Object depends on what type of data are you sending into your adapter.

Upvotes: 1

Related Questions