I have a SimpleCursorAdapter Class, and I want to set an OnItemClick method everytime when the row is clicked.
The method looks like this:
protected void onItemClick(AdapterView<?> l, View v, int position, long id) {
Intent listIntent = new Intent(DetailsActivity.class,this);
listIntent.putExtra("spendino.de.ProjectDetail.position",position);
listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
Provider.CONTENT_URI, Database.Project.NAME), Long
.toString(id)));
startActivity(listIntent);
}
but it always gives me an error on this line: Intent listIntent = new Intent(DetailsActivity.class,this);
It asks me to remove the arguments.
Can anybody help me with this?
UPDATED
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View convertView = mInflater.inflate(R.layout.listitems, null);
convertView.setClickable(true);
convertView.setFocusable(true);
convertView.setBackgroundResource(android.R.drawable.menuitem_background);
convertView.setOnItemClickListener(ProjectsList.this);
return convertView;
}
the first solution gave me no error, but when I set the method on my View, it says that setOnItemClickListener is undefined for convertView
UPDATED
convertView.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), DetailsActivity.class);
myIntent.putExtra("spendino.de.ProjectDetail.position",position);
myIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
Provider.CONTENT_URI, Database.Project.NAME), Long
.toString(id)));
view.getContext().startActivity(myIntent);
}
});
setOnClickListener isn’t working, I got an error on ‘position’ and ‘id’ how should I declare it?
Because those 2 things are mainly found on the setOnItemClickListener method
this should be the other way around
or use
MyActivity.thisas first argument.use this.. onItemClickListener is for listView. but the convertView is only a list Item..