Reputation: 193
i'm new to android and Its developing.i have Listview .when i press the item of it.i want to show its name-String name.how do i do ? please find below the code i used.there im getting myItem in Toast values such as 0,1,2,3... instead of String names. please find below the code snippet.
menu2.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String selectedFromList = String.valueOf(menu2.getItemAtPosition(arg2));
ImageView imgbtn2 = (ImageView) arg1
.findViewById(R.id.imageView1);
Object item = arg0.getItemAtPosition(arg2);
final String myitem = item.toString();
imgbtn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { // TODO Auto-generated method
Toast.makeText(getActivity(),myitem, Toast.LENGTH_LONG).show();
}
});
Upvotes: 0
Views: 53
Reputation: 1513
If you want to get some from your list view item than its better go with the costume listview, In that you can handle all the event of component of your costume listview in getView() method for more follow this url
Upvotes: 0
Reputation: 6792
On Rehan's demand. ;-)
You should move the ImageView in getView method of the adapter and add a separate onClickListener to it.
Glad I was able to help. :)
Upvotes: 1
Reputation: 96
try this
String selectedFromList = (String) arg0.getItemAtPosition(arg2);
Upvotes: 1