【问题标题】:How to set selector in expandable listivew on Group in android如何在 android 组的可扩展列表视图中设置选择器
【发布时间】:2016-05-25 12:56:34
【问题描述】:

我想在其groupView 上设置选择器,但是当我单击groupView 上的选择器时,它会转到expandable listview. 中的childView。 这是我的expandable listview

     <ExpandableListView
        android:id="@+id/lvLeft"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="singleChoice"
        android:dividerHeight="0dp"
        android:listSelector="@drawable/group_indicator"
        android:transcriptMode="alwaysScroll
        />

这是我的 group_indication.xml。

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/normal" android:state_expanded="true"></item>
    <item android:drawable="@drawable/normal"></item>

</selector>

这是我的 normal.xml。

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/red" />

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />
</shape>

实际上,我想在可扩展列表视图中为groupView 设置自定义颜色,但是当我点击groupView 时,groupViewchildView 上设置了自定义颜色。我附上了我现在遇到的问题的屏幕截图,其中 Transaction History 是 GroupView 并且 My Transaction 是 childView 。请帮我解决这个问题。提前致谢。

【问题讨论】:

    标签: android android-widget selector expandablelistview


    【解决方案1】:

    我已经通过 Prakash Gavade 的回答解决了这个问题。 here is answer。在可扩展的 listiview 适配器中,我添加了以下代码。

         @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
        {
            TextView tvUserName = null;
            ImageView imgMenuIcon = null;
    
            View drawerView = convertView;
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            if (groupPosition == 0)
            {
                drawerView = inflater.inflate(R.layout.profile_image, parent, false);
                ImageView ivProfilePic = (ImageView) drawerView.findViewById(R.id.imgProfile);
                tvUserName = (TextView) drawerView.findViewById(R.id.tvFname);
                TextView tvLname = (TextView) drawerView.findViewById(R.id.tvLname);
            }
            else if(isExpanded){
                convertView.setBackgroundResource(R.color.gray);
            }
            return drawerView;
        }
    

    【讨论】:

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