【问题标题】:Click icon ExpandableListView单击图标 ExpandableListView
【发布时间】:2018-03-06 08:54:33
【问题描述】:

我有一个类MyAdapter,它扩展了BaseExpandableListAdapter。 我想要一个在ConstraintLayout 中带有TextView 和ImageButton 的项目。

功能:

 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 添加点击,则项目点击监听器不起作用。

【问题讨论】:

  • 请发布您的布局
  • 好的,用textview和imagebutton完成

标签: android expandablelistview expandablelistadapter


【解决方案1】:

若要在imgButton 上添加点击后让项目可点击,请将其声明为 ConstraintLayout

android:descendantFocusability="blocksDescendants" 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多