Android listview突出显示问题

Android listview突出显示问题,android,listview,highlighting,Android,Listview,Highlighting,我必须列出物品清单。以下是我的布局XML: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" andro

我必须列出物品清单。以下是我的布局XML:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal"
        android:background="#FFFFFF"
        android:stretchColumns="0">
        <TableRow 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center_horizontal"
            android:id="@+id/listbox">
            <LinearLayout
                android:layout_width="fill_parent"
                android:background="#FFFFFF"
                android:layout_gravity="center_horizontal"
                android:layout_height="fill_parent">
                    <ListView
                        android:id="@+id/android:list"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
                    </ListView>
                    <LinearLayout
                        android:id="@android:id/empty" 
                        android:layout_width="fill_parent"
                        android:background="#FFFFFF"
                        android:layout_gravity="center"
                        android:layout_height="fill_parent">
                        <TextView 
                            android:id="@+id/emptytext" 
                            android:paddingTop="100dp"  
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#818185"
                            android:textSize="25sp"
                            android:textStyle="bold"
                            android:background="#FFFFFF"
                            android:text="@string/empty_fav"
                            android:gravity="center_horizontal|center_vertical"
                            android:paddingLeft="6dip"
                        />
                    </LinearLayout>  
            </LinearLayout>         
        </TableRow>
</TableLayout>

它是R.layout.custom_list_item_1的xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:textSize="18sp"
    android:textStyle="bold"
    android:background="#FFFFFF"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>

这是我的密码

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.fav_layout);
        ....
        ........

        wordDataHelper = new WordDataHelper(getApplicationContext());
        favCursor  = wordDataHelper.getCursorFav();
        startManagingCursor(favCursor);

        favAdapter = new SimpleCursorAdapter(
                this, 
                R.layout.custom_list_item_1,
                favCursor,                                              
                new String[] {WordDataHelper.ENGWORD},           
                new int[] {android.R.id.text1});   

        setListAdapter(favAdapter);

        list = getListView();

        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                // TODO Auto-generated method stub

                showVideo(((TextView) view).getText());

            }});

        list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            // @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenu.ContextMenuInfo menuInfo) {
                menu.setHeaderTitle("Context Menu");
                menu.add(0, CONTEXT_DELETE, 1, "Delete Item");
            }
        });

        list.setTextFilterEnabled(true);

        list.setClickable(true);
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fav_layout);
....
........
wordDataHelper=新的wordDataHelper(getApplicationContext());
favCursor=wordDataHelper.getCursorFav();
startManagingCursor(favCursor);
favAdapter=新的SimpleCursorAdapter(
这
R.layout.custom_list_item_1,
费克斯,
新字符串[]{WordDataHelper.ENGWORD},
新的int[]{android.R.id.text1});
setListAdapter(FavaAdapter);
list=getListView();
list.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父视图、视图、整型位置、,
长id){
//TODO自动生成的方法存根
showVideo(((TextView)view.getText());
}});
setOnCreateContextMenuListener(新的OnCreateContextMenuListener(){
//@覆盖
public void onCreateContextMenu(ContextMenu,视图v,
ContextMenu.ContextMenuInfo menuInfo){
menu.setHeaderTitle(“上下文菜单”);
添加(0,上下文_删除,1,“删除项”);
}
});
list.setTextFilterEnabled(true);
list.setClickable(true);
}
现在一切都很好,所有其他功能也很好 工作很好。但是,如果我触摸任何一行,它都不会突出显示 i、 颜色没有改变。我的代码或密码有问题吗
是否必须单独实施?如果是,如何设置?

您可能需要设置

android:listSelector
属性

检查这个答案,解释得很好


如果这不起作用(我还没有尝试过),请尝试将颜色选择器设置为R.layout.custom_list_item_1中定义的TextView的背景。问题是您正在将默认背景绘制覆盖为纯颜色,而纯颜色不支持状态(单击、聚焦等)。如果您希望背景为白色,最好只使用一个“浅色”Android主题,例如
@Android:style/Theme.light.NoTitleBar

尝试删除TextView项目的背景色:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>