ExpandableListActivity
にはContextMenu
が登録されています。私がしようとしているのは、ContextMenu
が押されたグループの子リスト項目のデータを保存することです。 によると:ExpandableListActivityでのContextMenuのトラブル
onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
v
は、コンテキストメニューが構築されている図です。だから、このビューは、私がクリックするリスト項目のものでなければなりませんが、それは子リストの最初のリスト項目を参照しています。私はそれがコンテキストメニューが構築されているリスト項目のビューを返す必要があると信じていますが、ここではそうではありません。ここに私のコードです:
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;
}
};
アダプタでリスト項目をリサイクルするときに問題が発生することがあります。あなたもそのコードを共有していただけますか?ありがとう! – rekaszeru
ここに私が使用しているアダプタのコードがあります。助けてくれてありがとうございます – rogerstone
あなたの 'viewBinder'には何が定義されていますか?あなたは 'BaseExpandableListAdapter'実装を使うことができました。それはかなり明確になります – rekaszeru