1

こんにちは、私のアプリケーションでは、expandableListView を使用しています。展開可能な listView の contextMenu を統合する必要があります。私の拡張可能な ListView では、さまざまな子のさまざまなレイアウトを膨らませます。そのため、各 childView を長押しすると、別のアクションを実行する必要があります。

ここで、ContextMenu のコードを示します。

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ExpandableListView.ExpandableListContextMenuInfo info=
            (ExpandableListView.ExpandableListContextMenuInfo)menuInfo;
    int type=ExpandableListView.getPackedPositionType(info.packedPosition);
    Log.e("type",""+type);
    menu.setHeaderTitle("Options");
    menu.add(1, 1, 1, "Edit");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo)item.getMenuInfo();

    if(item.getItemId()==1)
    {
        Log.e("clickd","menu");
    }
    return super.onContextItemSelected(item);
}

私の onCreate() で、ListView forContextMenu を登録します。

registerForContextMenu(expListView);

しかし、GroupView を押すと、contextMenu が表示されます。しかし、childViewをクリックすると、ContextMenuが表示されません..助けてください.....

4

3 に答える 3

3

私のために働いたこれを使用してください。アダプターを Expandable ListView に設定したら、それを書き込みます。

setListAdapter(expListAdapter);
            registerForContextMenu(getExpandableListView());
于 2013-04-10T05:41:36.210 に答える
2

getChildView(...)また、アダプターでビューを長くクリックできるように設定する必要があります。

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ... 
    convertView.setLongClickable( true);
于 2015-06-21T11:55:46.847 に答える