我有一个带有自定义适配器的列表视图,
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;
}
行布局
<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>
我有一个 onItemLongClickListener
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
---
view.setSelected(true);
}
当长按 TextView 但未响应长按 myView 时,将调用此侦听器。
我是否需要在 rowlayout 中设置 myView 的一些 xml 属性,以便在长按 myView 时选择一行?
触摸 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;
}