[TextView TextView ImageButton]を使用してAndroidにリストビューを持っています。ArrayAdapter を使用してリスト ビューを実装します。私の要件に従って、リストビューにはシングルプレスイベントとロングプレスイベントが必要なので、長押しにはregisterForContextMenu(getListView())を使用し、シングルプレスにはonListItemClickを使用します。これはうまくいきました。その後、リストビューのimageButtonのonClickイベントと、imageButtonのonclickを実装する必要があります。
今、私の問題は、listView の imageButton に onClick リスナーを実装した後、シングル プレス イベントと長押しイベントが機能しないことです。しかし、ImageButton onClick リスナーは正常に機能しています。
プロパティandroid:focusable="false"を imageButton に追加しましたが、役に立ちません。
ImageButton の onclick リスナーで単一および長押しイベントを取得するにはどうすればよいですか? 助けてください。
group.xml:
......
<ListView
android:id="@id/android:list"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
.....
group_row.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
......
android:focusable="false" />
<ImageButton
android:id="@+id/group_row_gadd"
.....
android:focusable="false"
android:background="@drawable/add" />
<TextView
android:id="@+id/group_row_grow"
....
android:focusable="false" />
</RelativeLayout>
私のarrayadapterクラス:
public class GroupAdapter extends ArrayAdapter<String> implements OnClickListener{
....
@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.group_row, parent, false);
name = (TextView) rowView.findViewById(R.id.group_row_gname);
number = (TextView) rowView.findViewById(R.id.group_row_grow);
add = (ImageButton) rowView.findViewById(R.id.group_row_gadd);
add.setTag(position);
add.setOnClickListener(this);
return rowView;
}
public void onClick(View v) {
Log.e("onclick", "onclick");
Integer position = (Integer) v.getTag();
switch (v.getId()) {
case R.id.group_row_gadd:
break;
}
}
}
メインクラス:
public class Group extends ListActivity{
.....
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.group);
registerForContextMenu(getListView());
.....
}// OnCreate End
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
.....
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.group_edit_remove, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
.....
return false;
}
}