gpt4 book ai didi

android - ExpandableListActivity 中 ContextMenu 的问题

转载 作者:行者123 更新时间:2023-11-30 04:41:55 24 4
gpt4 key购买 nike

ExpandableListActivity 中,我注册了一个 ContextMenu。我想要做的是存储按下 ContextMenu 的组的子列表项的数据。根据:

onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)

v 是为其构建上下文菜单的 View 。所以这个 View 应该是我点击的列表项的 View ,但它不是,它指的是子列表中的第一个列表项。我相信它应该返回为其构建上下文菜单的列表项的 View ,但这里不是这种情况。这是我的代码:

public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("My Crumbs");

TextView rowid = (TextView) v
.findViewById(R.id.trackdetails_item_row_id);
rowId = rowid.getText().toString();

ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
int type = ExpandableListView
.getPackedPositionType(info.packedPosition);

// Only create a context menu for the child
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {

TextView trackstats = (TextView) v
.findViewById(R.id.trackdetails_item_stats);
menu.add(0, MENU_SHARE, 0, "Share on Facebook");
}

}

有人可以阐明这一点吗?

编辑:

ExpandableListAdapter 的代码:

public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {

public MyExpandableListAdapter(Cursor cursor, Context context,
int groupLayout, int childLayout, String[] groupFrom,
int[] groupTo, String[] childrenFrom, int[] childrenTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childrenFrom, childrenTo);
setViewBinder(viewBinder);
}

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
// TODO Auto-generated method stub
String crumbName = groupCursor.getString(mCrumbNameColumnIndex);
return crumpareDBAdapter.getTrackList(mTracksProjection, crumbName);
}

@Override
public SimpleCursorTreeAdapter.ViewBinder getViewBinder() {
return viewBinder;
}

}

ViewBinder 的代码:

SimpleCursorTreeAdapter.ViewBinder viewBinder = new ViewBinder() {

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
// TODO Auto-generated method stub
TextView textView = (TextView) view;
textView.setText(cursor.getString(columnIndex));
return true;
}
};

最佳答案

您也可以从 ContextMenuInfo 中获取子项的 ID,而不是依赖于 View 。查看documentation因为它应该有你想要的。

关于android - ExpandableListActivity 中 ContextMenu 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5841522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com