侦听器无法识别ExpandableListView OnLongClick [英] ExpandableListView OnLongClick not recognized by listener
问题描述
我尝试了几种不同的组合(下面的注释是其中的一部分).调试无法识别点击.该项目突出显示,但没有任何反应.我试过膨胀自定义的row.xml文件,并在行布局文件中也使用视图.没有例外,没有更多的想法.感谢您的光临.
I have tried several different combinations (comments below are fragments of this). Debug doesn't recognize the click as ever happening. The item highlights, but nothing happens. I have tried inflating the custom row.xml file and using the views inside row layout file as well. No exceptions, no more ideas. Thanks for looking.
此外,我意识到onCreateContextMenu方法有点轻巧.我只是想让东西弹出,然后我会处理细节!
主要活动
public class BrowseActivity extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse);
final ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);
DbHelper dbh = new DbHelper(BrowseActivity.this);
SQLiteDatabase db = dbh.getWritableDatabase();
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(Items.ITEMS_TABLE_NAME);
Cursor mCursor = queryBuilder.query(db, new String[] { Items.ITEMS_ID,
Items.ITEMS_ITEM, Items.ITEMS_DESC }, null, null, null, null,
Items.DEFAULT_SORT_ORDER);
CursorTreeAdapter mAdapter = new MyExpandabaleListAdapter(this,
mCursor, R.layout.row, R.layout.exprow, new String[] {
Items.ITEMS_ITEM, Items.ITEMS_DESC }, new int[] {
R.id.txtItem, R.id.dscItemTwo }, new String[] {
Items.ITEMS_DESC, Items.ITEMS_MANU }, new int[] {
R.id.dscItem, R.id.manuItem });
browseView.setAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
public class MyExpandabaleListAdapter extends SimpleCursorTreeAdapter {
public MyExpandabaleListAdapter(Context context, Cursor c,
int groupLayout, int childLayout, String[] groupFrom,
int[] groupTo, String[] childrenFrom, int[] childrenTo) {
super(context, c, groupLayout, groupFrom, groupTo, childLayout,
childrenFrom, childrenTo);
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {...}
}
public void OnCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, 0, 0, "Add");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Add Item").setIntent(new Intent(this, AddItemActivity.class));
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
return false;
}
}
浏览器布局 这是用于存放ELV的布局.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="@+id/expandLinLayout"
>
<ExpandableListView
android:id = "@android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:groupIndicator="@drawable/my_group_statelist"
>
</ExpandableListView>
</LinearLayout>
行布局 这是折叠后的布局.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_gravity="center_vertical|right"
android:id="@+id/txtItem"
android:text="Item"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="15dip"
></TextView>
<TextView
android:layout_gravity="center_vertical|right"
android:id="@+id/dscItemTwo"
android:text="Desciption"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textStyle="italic"
android:textColor="#666666"
></TextView>
展开布局 这是展开的布局.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/manuItem"
android:textColor="#994020"
android:text="Manufacturer"
android:layout_marginRight="10dip"
></TextView>
<TextView
android:text="Description"
android:id = "@+id/dscItem"
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dip"
android:textColor="#994020"
></TextView>
</LinearLayout>
推荐答案
在您的 registerForContextMenu ()您是否不必传递声明的列表:
In your registerForContextMenu()do you not have to pass in the declared list:
registerForContextMenu(getListView());
http://developer.android.com/reference/android/app/ListActivity.html#getListView()
或您的情况:
StackOvflow参考:如何实现Android上的ListActivity中的上下文菜单?
StackOvflow reference: How do you implement context menu in a ListActivity on Android?
这篇关于侦听器无法识别ExpandableListView OnLongClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!