我有Android的列表視圖[TextView TextView ImageButton]。我通過使用ArrayAdapter實現列表視圖。根據我的要求,我需要單擊和長按事件列表視圖,以便我使用registerForContextMenu(getListView())長按和單按我使用onListItemClick。 這工作正常。之後,另外我需要列表視圖上的imageButton onClick事件,併爲imageButton實現onclick。單擊和長按不工作後在listView中實現imageButton的onclick監聽器在Android
現在我的問題是單擊新聞事件和長按事件不工作後onClickView.But ImageButton實現onClick監聽器onClick監聽器工作正常。
我添加屬性機器人:可調焦=「假」到ImageButton的,但它並不能幫到我。
如何使用onclick偵聽器爲ImageButton獲取單次和長按事件?請求幫助我。
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;
}
}
}
mainclass:
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;
}
}
我試過你的答案,但不工作請幫我 – 2012-03-13 08:09:37