我有一个MyAdapter
课,它扩展了BaseExpandableListAdapter
。
我希望TextView
中包含ImageButton
和ConstraintLayout
的商品。
功能:
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (ConstraintLayout) activity.getLayoutInflater().inflate(R.layout.constraint, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tv_mytext);
ImageButton imgBtn = (ImageButton) convertView.findViewById(R.id.img_btn_my);
if (tv != null) tv.setText("MyText");
if (imgBtn != null) imgBtn.setOnClickListener(.....);
return convertView;
}
布局:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginTop="2dp"
android:background="@drawable/selector_item_black"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:textAppearance="?android:attr/textAppearanceMedium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/img_btn_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_expand_more" />
</android.support.constraint.ConstraintLayout>
最好的方法是:
imgButton
如果我在imgButton
上添加一个点击,那么项目点击监听器就不起作用。
答案 0 :(得分:1)
要在imgButton
上添加点击后点击该项目,请将其声明为 ConstraintLayout
android:descendantFocusability="blocksDescendants"