我设法让我的Listview行填充了Image按钮和 因为我添加了
机器人:descendantFocusability = “blocksDescendants”
到row.xml,我可以同时点击两个监听器(ImageButton和Listview行)
但在特殊情况下,我现在希望Listview单击侦听器也对ImageButton单击区域做出反应。 (就好像Imagebutton不存在一样)这可能吗?
fragment.java:
myList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
doRowOnClickStuff();
return true;
}
});
listAdapter.java
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, final ViewGroup parent) {Charakter charakter = (Charakter) getGroup(groupPosition);
if(convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.group_row, parent, false);
}
TextView heading = (TextView) convertView.findViewById(R.id.heading);
final ImageButton imageButton = (ImageButton) convertView.findViewById(R.id.groupimagebutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
//in some cases, I want to call the Listview click listener and not imageButton click listener
}
答案 0 :(得分:0)
不知道这是不是一个好的做法,但它的工作原理如下:
imageButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
ExpandableListView myList = (ExpandableListView) parent.findViewById(R.id.expandableList);// get reference to the ExpandableListView
myList.performItemClick(view, myList.getPositionForView(view), getGroupId(groupPosition));
}
});