我在我的活動中有可擴展的列表視圖。我想爲孩子們展示一個contextmenu。基本上我知道如何做到這一點,但是在實施contextmenu時,它從不顯示子視圖。只是長時間點擊組視圖,我沒有找到這種行爲的原因。任何想法也許? 在此先感謝!沒有顯示可擴展列表視圖的子菜單
建立可擴展列表視圖:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View v = inflater.inflate(R.layout.listed_data, container, false);
parser = new SvwXmlparser("a", getSherlockActivity());
elv = (ExpandableListView) v.findViewById(R.id.svwexplist);
return v;
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
registerForContextMenu(elv);
infos = parser.parse();
showData();
}
public void showData()
{
adapter = new SvwInfoAdapter(getSherlockActivity(), infos);
elv.setAdapter(adapter);
}
適配器:
public Object getChild(int groupPos, int childPos) {
return children.get(groupPos).get(childPos);
}
public long getChildId(int groupPos, int childPos) {
return childPos;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
//TODO:modify
String player = (String)getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.svw_team_child_layout, null);
}
convertView.setFocusableInTouchMode(true);
TextView players = (TextView) convertView.findViewById(R.id.tvteamChild);
/*if(childPosition> 1)
{
players.setText((childPosition-1) + ". " + player);
}
else
{
players.setText(player);
}*/
players.setText(player);
return convertView;
}
public int getChildrenCount(int groupPos) {
return children.get(groupPos).size();
}
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
創建文本菜單:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
Toast toas =Toast.makeText(getSherlockActivity(), groupPos + " - " + childPos, Toast.LENGTH_LONG);
toas.show();
的祝酒會爲每個組而不是爲了孩子...
我不認爲我看不到任何東西在這裏,會造成麻煩。沒有'setFocusableInTouchMode'調用可能值得嘗試。另外,我不認爲xml部分是相關的。你可以顯示你創建的位置並設置ExpandableListView嗎?你設置了一個長的點擊處理程序? – dokkaebi
我只是註冊上下文菜單。我之前沒有使用setFocusableInTouchMode嘗試它,這沒有任何不同。我調整了上面的代碼片段。 –
我剛剛將您的代碼添加到其中一個ExpandableListViews,並且它工作正常。我爲兩個小組和兒童都敬酒,否則他們的行爲會正常。它可能與你的列表的選擇模式有關 - 我必須將我的調用刪除到'listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);'。否則,也許它與sherlock有關?也許sherlock自動設置一個上下文動作欄或其他東西? – dokkaebi