带ImageButton的Listview,想在ImageButton中调用Listview点击监听器
Listview with ImageButton, want to call Listview Click in ImageButton click Listener
我设法让我的列表视图行填充了图像按钮和
因为我添加了
android: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
}
不知道这是否真的是一个好习惯,但它是这样工作的:
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));
}
});
我设法让我的列表视图行填充了图像按钮和 因为我添加了
android: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
}
不知道这是否真的是一个好习惯,但它是这样工作的:
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));
}
});