【问题标题】:want to change the color of text in multiple choice listview想要更改多项选择列表视图中文本的颜色
【发布时间】:2012-05-02 10:55:37
【问题描述】:

我有如图所示的多项选择列表

我有两个问题

  1. 但在我的所有应用程序屏幕中都有白色背景。如果我将屏幕设为白色,所有文本“BlackBerry”、“Nokia”等都消失了,因为默认情况下文本颜色为白色。 . 所以请告诉我如何将文本颜色更改为黑色?我尝试了样式,但它不起作用。

  2. 我得到的检查位置有一些问题..例如如果选中其中一项,稍后如果我未选中,即使未选中,它仍然显示该项目已被选中..

这是我的检查项目选择代码

private void doDownloading() {
        SparseBooleanArray sp = listTrackView.getCheckedItemPositions();

        for (int i = 0; i < sp.size(); i++) {
            selectedConferenceList.add(conferenceList.get(sp.keyAt(i))
                    .getConferenceName());
        }

}

【问题讨论】:

    标签: android listview


    【解决方案1】:

    这是一个示例代码,您可以根据自己的需要进行更改

    AndroidMultiChoiceListActivity .java

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    public class AndroidMultiChoiceListActivity extends Activity {
    
     ListView choiceList;
     String[] choice = { "Choice A", 
       "Choice B", "Choice C", "Choice D", "Choice E"};
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            choiceList = (ListView)findViewById(R.id.list);
    
            ArrayAdapter<String> adapter
            = new ArrayAdapter<String>(this, 
              android.R.layout.simple_list_item_multiple_choice, 
              choice);
            choiceList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            choiceList.setAdapter(adapter);
    
        }
    }
    

    ma​​in.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        android:textColor="#334422"
        />
    <ListView 
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    </LinearLayout>
    

    在您的 Textview 中使用 android:textColor="#334422" 更改文本颜色。

    【讨论】:

    • 随心所欲更改颜色
    • 我已经实现了它..但是我需要对其进行自定义..仔细阅读问题
    • 在哪里更改文本颜色,在 xml 中的任何一个活动?
    • 在我提到“Blackberry”、“Nokia”等的列表中。关键是我没有实现自定义适配器,而是我有 ArrayAdadpter..
    • 我希望在您的自定义适配器中您肯定使用 textview,对吗?
    【解决方案2】:

    最后我知道没有办法使用标准ArrayAdapter&lt;String&gt; 更改多项选择列表视图的文本颜色。所以我去定制适配器实现。 This 链接有助于我开发具有多项选择实现的自定义适配器。

    【讨论】:

      猜你喜欢
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      相关资源
      最近更新 更多