Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 可扩展列表视图的选择器-Android 2.3+;_Java_Android_Selector - Fatal编程技术网

Java 可扩展列表视图的选择器-Android 2.3+;

Java 可扩展列表视图的选择器-Android 2.3+;,java,android,selector,Java,Android,Selector,我正在尝试将选择器添加到可扩展的listview 我有一个背景,文字颜色和图像,我需要改变状态时,该项目被选中 这是我的分组项目布局 <?xml version="1.0" encoding="utf-8"?> <com.example.views.CheckedRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_par

我正在尝试将选择器添加到可扩展的listview

我有一个背景,文字颜色和图像,我需要改变状态时,该项目被选中

这是我的分组项目布局

<?xml version="1.0" encoding="utf-8"?>
<com.example.views.CheckedRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@color/selector_menu_item_bg"
    android:minHeight="48dp"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/ic_menu"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:background="@color/selector_menu_item_pic" />

    <com.example.views.CheckedTextView
        android:id="@+id/txt_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:layout_toRightOf="@+id/ic_menu"
        android:text="Dashboard"
        android:textColor="@color/selector_menu_item_txt"
        android:textSize="16dp" />

    <ImageView
        android:id="@+id/ic_drop_down_arrow"
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_play_down" />

</com.example.views.CheckedRelativeLayout>
按下状态工作,但按下时不保持状态

目前我使用

listMenu.setItemChecked(selectedMenuItem, true);
但不幸的是,在安卓4.4上,我的背景一直高亮显示,但文本视图和图像视图都没有。 在api 8上,甚至背景也没有高亮显示

我已经看过这个了
但是,我无法让它与可扩展的listview一起工作

我遇到了同样的问题,我使用自定义代码高亮显示了所选的expListview。如果有一个标准答案,那就好了。你能发布你的解决方案吗。让我试着为你做这件事。可能的重复是重复的,但我仍然没有找到答案,通常在这里,如果你在发布问题的一天内不帮忙,它会被推到底部,并且永远不会被回答。。
private StateListDrawable getStatesForPageId(PageId pageId) {
        StateListDrawable states = new StateListDrawable();
        switch (pageId) {
        case HOME:
            states.addState(
                    new int[] { android.R.attr.state_pressed },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_dashboard_active));
            states.addState(
                    new int[] { android.R.attr.state_activated },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_dashboard_active));
            states.addState(
                    new int[] { android.R.attr.state_checked },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_dashboard_active));
            states.addState(
                    new int[] {},
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_dashboard));
            break;

        case PAGE_1:
            states.addState(
                    new int[] { android.R.attr.state_pressed },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_transfer_active));
            states.addState(
                    new int[] { android.R.attr.state_activated },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_transfer_active));
            states.addState(
                    new int[] { android.R.attr.state_checked },
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_transfer_active));
            states.addState(
                    new int[] {},
                    context.getResources().getDrawable(
                            R.drawable.ic_menu_transfer));
            break; 
 }
}
listMenu.setItemChecked(selectedMenuItem, true);