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.
Also, I realize the onCreateContextMenu method is a little light. I just want to get the thing to pop up, then I will take care of the details!
Main Activity
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;
}
}
browse layout This is the layout the holds the 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>
row layout This is the collapsed layout.
<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>
exprow layout This is the expanded layout.
<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>
Background reading
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()
or in your case:
http://www.androidjavadoc.com/1.0_r1_src/android/app/ExpandableListActivity.html#getExpandableListView()
StackOvflow reference: How do you implement context menu in a ListActivity on Android?
精彩评论