OnItemClickListener and OnClickListener not working for ListView
The following will do the job in your case.
ListView propertylistview = (ListView) findViewById(R.id.listview);
propertylistview.setOnItemClickListener( myListViewClicked ):
OnItemClickListener myListViewClicked = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(YourActivity.this, "Clicked at positon = " + position, Toast.LENGTH_SHORT).show();
}
};
Dont forget to remove the following from the CustomAdapter
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(parent.getContext(), "view clicked: " + ListArray.getName(), Toast.LENGTH_SHORT).show();
}
});
If the touch events are getting intercepted inside the cell layout, in the layout for your custom cell, set
android:descendantFocusability="blocksDescendants"
on the top level layout of your cell. For me, it was too much of a pain to add xml attributes to every individual view.
Note that this can also be set in code:
cell.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
I also tried this with a ListView inside a cell, and I had to override onTouchEvent to get it to work:
public class NoTouchListView extends ListView {
@Override
public boolean onTouchEvent(MotionEvent ev) {
return false;
}
}
the simple code that solved my problem, and method view.setOnClickListener be within my custom adapter
view.setFocusable(false)