how to get data from listview by clicking item on listview

17,007

Solution 1

Try this:

my_listview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              

            }
        });

In a few days we will be uploading an elaborate tutorial on http://p-xr.com. Be sure to check it out :)

Solution 2

You need to set itemclicklistener to listen all item click events. Add this code to the above code

lv.setClickable(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Object o = lv.getItemAtPosition(position);
String str=(String)o;//As you are using Default String Adapter
/* write you handling code like...
// do whatever u want to do with 'f' File object
*/ 
}
});

Solution 3

We can directly use the View parameter inside the onItemClick() to get the value from that item in list. Try this....

mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
    public void onItemClick(AdapterView<?> parent,View view,int position,long id)
    {
    TextView textview =((TextView)view.findViewById(R.id.tvInVisitorName)).getText().toString();
    }
    });

I am taking the value form the item of list in the textview

Share:
17,007
Hip Hip Array
Author by

Hip Hip Array

Updated on June 04, 2022

Comments

  • Hip Hip Array
    Hip Hip Array almost 2 years

    I have a listview in my application and its populated with all the currently installed applications on my device, also i have it getting the list of permissions from all the installed applications.

    My question is how do i get the listview clickable so that i can get the list of permissions for the application you click on in the listview?

    Could someone please help?