问题描述
我使用 ExpandableListview
动态从服务器。数据显示
我用组标题
和子布局
选择,但我不能发现任何反映选择。
请帮助我如何完成这件事。
先谢谢了。
row_highlighter.xml
<?XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:exitFadeDuration =@安卓整数/ config_mediumAnimTime> <项目机器人:可绘制=@机器人:彩色/ holo_blue_bright机器人:STATE_ pressed =真/>
<项目机器人:可绘制=@机器人:彩色/ holo_blue_light机器人:state_selected =真/>
<项目机器人:可绘制=@机器人:彩色/ holo_blue_dark机器人:state_activated =真/>
< /选择>
ExpandableListviewDemo.java
expListView.setOnGroupClickListener(新OnGroupClickListener(){ @覆盖
公共布尔onGroupClick(ExpandableListView父视图V,INT groupPosition,长ID){ INT指数= parent.getFlatListPosition(ExpandableListView.getPackedPositionForGroup(groupPosition));
parent.setItemChecked(指数,真正的);
返回false;
}
}); //点击儿童
expListView.setOnChildClickListener(新OnChildClickListener(){
@覆盖
公共布尔onChildClick(ExpandableListView父视图V,INT groupPosition,诠释childPosition,长ID){
INT指数= parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition,childPosition));
parent.setItemChecked(指数,真正的);
返回true;
}
});
activity_demo.xml
< ExpandableListView
机器人:ID =@ + ID / search_expandable_listview
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_gravity =开始
机器人:choiceMode =singleChoice
机器人:分=@彩色/ list_divider
机器人:childDivider =@绘制/ listview_divider
机器人:dividerHeight =1DP
机器人:listSelector =@绘制/ row_highlighter
机器人:背景=@彩色/ list_background
机器人:layout_below =@ + ID / search_header
机器人:layout_above =@ + ID / layout_option_buttons
机器人:scrollingCache =假
机器人:transcriptMode =已禁用
机器人:fastScrollEnabled =假
机器人:smoothScrollbar =真
机器人:fastScrollAlwaysVisible =假
机器人:animationCache =假
机器人:persistentDrawingCache =无
机器人:alwaysDrawnWithCache =假
机器人:drawingCacheQuality =低/>
您选择缺少默认选择把默认的颜色像下面,而不是在ExpandableList增加选择尝试将它作为的rootView背景的父母与子女的布局。
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:exitFadeDuration =@安卓整数/ config_mediumAnimTime> <项目机器人:可绘制=@机器人:彩色/ holo_blue_bright机器人:STATE_ pressed =真/>
<项目机器人:可绘制=@机器人:彩色/ holo_blue_light机器人:state_selected =真/>
<项目机器人:可绘制=@机器人:彩色/ holo_blue_dark机器人:state_activated =真/>
<项目机器人:可绘制=@机器人:彩色/透明/>
< /选择>
I am using ExpandableListview
that displays data dynamically from server.
I used selector for Group Header
and Child Layout
, but I can't notice any selector that reflects.
Pls help me how to get this done.
Thanks in advance.
row_highlighter.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@android:color/holo_blue_bright" android:state_pressed="true"/>
<item android:drawable="@android:color/holo_blue_light" android:state_selected="true"/>
<item android:drawable="@android:color/holo_blue_dark" android:state_activated="true"/>
</selector>
ExpandableListviewDemo.java
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) {
int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForGroup(groupPosition));
parent.setItemChecked(index, true);
return false;
}
});
// Clicking on Child
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {
int index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
parent.setItemChecked(index, true);
return true;
}
});
activity_demo.xml
<ExpandableListView
android:id="@+id/search_expandable_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:childDivider="@drawable/listview_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/row_highlighter"
android:background="@color/list_background"
android:layout_below="@+id/search_header"
android:layout_above="@+id/layout_option_buttons"
android:scrollingCache="false"
android:transcriptMode="disabled"
android:fastScrollEnabled="false"
android:smoothScrollbar="true"
android:fastScrollAlwaysVisible="false"
android:animationCache="false"
android:persistentDrawingCache="none"
android:alwaysDrawnWithCache="false"
android:drawingCacheQuality="low"/>
Your selector is missing the default selector put the default color like below, instead of adding the selector in the ExpandableList try adding it as a background for the rootView of your Parent and Child layouts.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@android:color/holo_blue_bright" android:state_pressed="true"/>
<item android:drawable="@android:color/holo_blue_light" android:state_selected="true"/>
<item android:drawable="@android:color/holo_blue_dark" android:state_activated="true"/>
<item android:drawable="@android:color/transparent" />
</selector>
这篇关于listSelector的组头和子布局的ExpandableListview不能正常工作的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!