I have a list view with custom Adapter,
public class ClueArrayAdapter extends ArrayAdapter<String> {
---
----
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
---
---
return rowView;
}
rowlayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/clue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<com.mydomain.MyView
android:id="@+id/myView" // MyView is custom view and overrides onTouchEvent
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
I have a onItemLongClickListener
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
---
view.setSelected(true);
}
This listener is getting invoked when there is a long click on TextView but not responding to long click on myView.
Do i need to set some xml attributes of myView in rowlayout so that a row is selected in responce to a long click on myView too ?
on touch of myView
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
markedCell = getCellAt(x,y);
break;
}
}
return true;
}
Return false from your onTouchEvent.
Returning true means that you handled the event and that it shouldn’t be passed to the next handler (in this case, your long touch event).