カスタム アダプタを使用したリスト ビューがありますが、
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 を長押ししても応答しません。
myView の長いクリックに応答して行が選択されるように、rowlayout で myView のいくつかの xml 属性を設定する必要がありますか?
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;
}