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?
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
*/
}
});
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
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 :)
精彩评论