2011-07-09 26 views
0

我嘗試了幾種不同的組合(下面的評論是這個的片段)。調試不能識別點擊一直髮生。該項目突出顯示,但沒有任何反應。我已經嘗試使用自定義row.xml文件並使用行佈局文件中的視圖。沒有例外,沒有更多的想法。感謝您的期待。ExpandableListView OnLongClick不被聽衆識別

此外,我意識到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> 

exprow佈局這是擴張佈局。

<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> 
+0

我是啞巴,哪來的長按的方法? – Blundell

+0

我懷疑你是愚蠢的,我是一個有26的差點的人。我假設它包含在registerForContextMenu()中,我認爲我讀了某處...?.. – atomSmasher

+0

啊是的,爲什麼你註釋掉了你的列表上的上下文,現在反而誇大了一些其他觀點?我認爲這是你的錯誤。 – Blundell

回答

1
+0

這不適合我。 9個小時後,我放棄了使用setOnCreateContextMenuListener()代替registerForContextMenu()和onCreateContextMenu()。現在工作正常,不知道爲什麼,但它的工作原理。 – atomSmasher