没有上下文菜单显示为可扩展列表视图的孩子 [英] No context menu is shown for child of expandable listview
问题描述
我有我的活动可扩展列表视图。我想,以示对孩子的一个文本菜单。基本上我知道如何做到这一点,但实施contextMenu当它从来没有显示出来为孩子的意见。只是在组视图长的点击和我没有找到这种现象的原因。任何想法可能?
在此先感谢!
I'm having an expandable listview in my activity. I want to show a contextmenu for the childs. Basically I know how to do this, but when implementing the contextmenu it never shows up for the child views. Just for long clicks on the group view and I didn't find the reason for this behavior. Any ideas maybe? Thanks in advance!
设置的扩展列表视图:
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();
的吐司显示对于每个组,但不为孩子...
The toast shows for every group but not for the children...
推荐答案
我终于理解了它...它不工作设置可触摸=在XML假的。调用适配器的getView的方法为组和子视图setTouchable(假)后,一切工作像预想的那样。
I finally figured it out... It's not working to set touchable=false in the xml. After calling setTouchable(false) in the adapter's getView-methods for group and child view, everything is working as supposed.
这篇关于没有上下文菜单显示为可扩展列表视图的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!