Hip Hip Array
Hip Hip Array

Reputation: 4753

how to get data from listview by clicking item on listview

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?

Upvotes: 3

Views: 17949

Answers (3)

Android007
Android007

Reputation: 155

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

Upvotes: 1

Kartik Domadiya
Kartik Domadiya

Reputation: 29968

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
*/ 
}
});

Upvotes: 3

Mark Mooibroek
Mark Mooibroek

Reputation: 7696

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 :)

Upvotes: 0

Related Questions