Image icon in expandable list view in android

前端 未结 4 774
谎友^
谎友^ 2021-02-06 10:37

I want to add an image icon in expandable list view .I have seen the tutorial they have added only in child elements .Is there any other way to add image icon in parent Any hel

相关标签:
4条回答
  • 2021-02-06 10:56
        indicator=(ImageView)convertView.findViewById(R.id.icon_img);
        if ( getChildrenCount( groupPosition ) == 0 ) {
            indicator.setVisibility( View.INVISIBLE );
        }
        else {
            indicator.setVisibility( View.VISIBLE );
            indicator.setImageResource( isExpanded ? 
           R.drawable.ic_arrow_up : R.drawable.ic_arrow_down );
        }
    
    0 讨论(0)
  • 2021-02-06 10:59

    ok

       public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
    
        if(getChildrenCount(groupPosition)==0)
        {
              // how do i hide the group indicator ?
    
        }
    

    So, how can modify the group indicator for empty groups ?

    0 讨论(0)
  • 2021-02-06 11:12

    You can try the setGroupIndicator(Drawable) method of ExpandableListView.

    0 讨论(0)
  • 2021-02-06 11:20

    You can also define your own groupIndicator in XML:

    First define your own drawable (I called it list_view_group_indicator.xml and placed it in the drawable directory)

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:state_expanded="true"
            android:drawable="@drawable/packagexgeneric" />
        <item
            android:drawable="@drawable/packagexgenericclose" />
    </selector>
    

    Then use it as a drawable for your expandableListview

    <ExpandableListView android:id="@+id/server_show_list"
        android:layout_width="fill_parent"android:layout_height="wrap_content"
        android:groupIndicator="@drawable/list_view_group_indicator" />
    
    0 讨论(0)
提交回复
热议问题