特定のボタンにonTouchListenerを使用し、xmlandroid:duplicateParentState
でも両方を使用することはありませんでした。android:addStatesFromChildren
CustomExpandableListAdapter で行ったことは次のとおりです。
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
/* code before */
ImageButton button = (ImageButton) convertViewNotNull.findViewById(R.id.ofButton);
button.setOnClickListener(onClickListenerInCodeBefore);
View.OnTouchListener onTouchCell = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
setPressedState(v, true);
break;
case MotionEvent.ACTION_UP:
setPressedState(v, false);
v.performClick();
break;
default:
break;
}
return true;
}
};
button.setOnTouchListener(onTouchCell);
}
// code can be optimized
private void setPressedState(View v, boolean pressed) {
ViewGroup parent = (ViewGroup) v.getParent();
final int count = parent.getChildCount();
for (int i = 0; i < count; i++) {
View view = parent.getChildAt(i);
view.setPressed(pressed);
if (view instanceof RelativeLayout ||
view instanceof LinearLayout) {
ViewGroup group = (ViewGroup) view;
final int size = group.getChildCount();
for (int j = 0; j < size; j++) {
View child = group.getChildAt(j);
child.setPressed(pressed);
}
}
}
}
これで、動作します。