Android Expandable lIst View Group展开Listener

时间:2017-02-09 07:12:37

标签: android

我在我的应用程序中使用可扩展列表视图,具有组展开和组折叠侦听器。  但是发生的事情是组行中的右箭头单击工作绝对完美,但是当我点击该行时,该组不会在单个clcik中展开。 我必须多次点击它,然后它才会扩展。 这是可扩展列表视图组单击侦听器代码:

expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
       @Override
       public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
              groupName = _groupNameList.get(i);
              _header = _child.get(groupName);

              if (_header.size() == 1 && _header.get(0).getServiceName().equals(groupName)) {
                   expandableListView.setGroupIndicator(null);
                   String id=_header.get(0).getServiceId();
                   Intent intent = new Intent(CategoryDetails1.this, ServiceSelectionOptionsListActivity.class);
                   SharedPreferences.Editor editor = CategoryDetails1.this.getSharedPreferences(AppConstants.VERIFICATION, CategoryDetails1.this.MODE_PRIVATE).edit();
                   editor.putString(AppConstants.SUBSERVICEID, id);
                   editor.commit();
                   startActivity(intent);

               }
               return false;
          }
 });

这里是标题行xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvGroupName"
        android:layout_width="match_parent"
        android:layout_marginLeft="20dp"
        android:textSize="18dp"
        android:layout_marginBottom="10dp"
        android:textStyle="bold"
        android:layout_marginRight="25dp"
        android:layout_alignParentLeft="true"
        android:inputType="textMultiLine"
        android:textColor="@color/selecteditem"
        android:layout_marginTop="10dp"
        android:layout_height="wrap_content"
        android:focusable="false"                         have tried this
        android:layout_weight="1" />

    <ImageView
        android:id="@+id/groupindicator"
        android:layout_width="30dp"
        android:layout_marginBottom="10dp"
        android:layout_height="30dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/circle_plus" />
</RelativeLayout>

这是我的getgroup视图方法

    public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.expandable_list_header, null);
        }
        TextView tvGroupName = (TextView) view.findViewById(R.id.tvGroupName);
        tvGroupName.setFocusable(false);             //have tried it also
        ImageView ivgroupicon = (ImageView) view.findViewById(R.id.groupindicator);
        // ivgroupicon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.servicescollapseicon));
        tvGroupName.setText((String) getGroup(groupPosition));
        int size = _child.get((String) getGroup(groupPosition)).size();
        view.setPadding(0, 10, 0, 10);
        if (size == 1 && _child.get((String) getGroup(groupPosition)).get(0).getServiceName().equals((String) getGroup(groupPosition))) {
            ivgroupicon.setVisibility(View.GONE);
        } else
            ivgroupicon.setVisibility(View.VISIBLE);
        if (b) {
            ivgroupicon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.servicesexpandicon));
        } else {
            ivgroupicon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.servicescollapseicon));
        }

        return view;
    }

现在我想要的是我希望在我的activity中平滑的组扩展和崩溃侦听器。我已经在我的xml和适配器文件中尝试了setFocusable为false但是在Vain中。 所以大家请尽快给我一些建议。很长一段时间我都陷入困境。

1 个答案:

答案 0 :(得分:0)

将以下属性添加到您的

TextViewImageView

android:focusable="false"

在根布局中:RelativeLayout

android:descendantFocusability="blocksDescendants"