setOnItemClickListener gives multiple error messages

  • Replies:3
Michael Mossman
  • Forum posts: 1

Oct 30, 2012, 11:51:11 AM via Website

I have been following a tutorial on ListView and the following code gives errors. I have searched all the forums I can find but I keep coming up with the same recommended code. Maybe all the forums are quoting old versions and perhaps Android has moved on.

Anyway, here is the code and the error message :-

getListView().setOnItemClickListener(new OnItemClickListener()
{
//@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
// TODO Sort out error and add function code
}
});

Error message :-

Multiple markers at this line

-The method setOnItemClickListener(AdapterView.OnItemClickListener in the type AdapterView <ListAdapter> is not applicable for the arguments (new OnItemClickListener(){})

-OnItemClickListener cannot be resolved to a type

Any offers ? Thanks, Mike

— modified on Oct 30, 2012, 11:52:41 AM

Reply
Ashish Tripathi
  • Forum posts: 211

Feb 4, 2013, 12:55:13 PM via Website

Check out the package you have imported for listener.

Reply
Sachin Sandbhor
  • Forum posts: 4

Feb 28, 2013, 4:30:24 PM via Website

Check out which interface is implemented.
here is the simple code for listview i used in my application.
MytList.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
case 0: (Toast);
}
});
o represent position in list
now use arg2 for position in list.

Reply
Ashish Tripathi
  • Forum posts: 211

Jul 24, 2013, 8:23:46 AM via Website

Just try one thing. Instead of extending the lisyview create it on xml than use it.
Share the activity code .

Reply