带有单选按钮的android listview不显示简单列表项单选项中的内容

时间:2012-03-01 06:09:17

标签: android listview radio-button

我正在尝试使用单选模式的单选按钮显示列表视图。

以下是我的代码

ListView l1 = (ListView)findViewById(R.id.listView1);

for(int i = 0; i <firstlist.size(); i++)
        {           
            f = firstlist.get(i);
            HashMap<String, Object> map = new HashMap<String, Object>(); 
            map.put("fname", f);
            listItem1.add(map);
        }
        SimpleAdapter listItemAdapter1 = new SimpleAdapter(this,listItem1,android.R.layout.simple_list_item_single_choice,new String[] {"fname"}, new int[] {R.id.fname});   
        l1.setAdapter(listItemAdapter1);
        l1.postDelayed(new Runnable() 
        {
            public void run() 
            {
                Utility.setListViewHeightBasedOnChildren(l1);
            }
        }, 400);
        l1.setItemsCanFocus(false);
        l1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

一切正常,但问题是布局的背景颜色为白色,我将listview颜色中的文本设置为黑色,但列表视图中的文本无法查看。

当我长按时,列表颜色会突出显示,然后只显示文本。当我发布它消失了。

如何将所选列表单选按钮颜色更改为红色,是否可以

如何使文本可见。

2 个答案:

答案 0 :(得分:0)

尝试将listview属性cacheColorHint设置为Transparent后,它对我有用。

答案 1 :(得分:0)

您可以使用数组适配器添加任何主题,但使用带有选择模式的简单列表时,无法更改文本颜色 但是数组适配器的问题是滚动复选框时取消选中

因此要解决,请在布局文件夹中创建一个xml文件 style_list.xml 将此代码粘贴到

  <CheckBox xmlns:android="schemas.android.com/apk/res/android";
       android:id="@android:id/text2" 
       android:paddingTop="10dip"
       android:paddingLeft="25dip"
       android:paddingBottom="10dip"
       android:layout_width="fill_parent" 
       android:textSize="15dip"
       android:layout_height="wrap_content" 
       android:background="#ffffffff"
       android:textColor="#000000"/>

and then change your adapter line code as 

 SimpleAdapter listItemAdapter1 = new SimpleAdapter(this,listItem1,R.layout.style_list,new String[] {"fname"}, new int[] {R.id.fname}); 

并用此

替换列表视图xml
 <ListView android:layout_width="fill_parent"
             android:layout_height="200dip"
             android:id="@+id/your_order_list"
             android:cacheColorHint="#ffffff"
             android:background="#ffffff"/>
相关问题