2012-05-02 100 views
0

我有多種選擇列表,如圖1所示想改變文本的顏色多選列表視圖

enter image description here

我有2個問題

  1. 但在我所有的應用程序屏幕有背景白色..這裏是相同的情況下,如果我使我的屏幕白色,所有文字「黑莓」,「諾基亞」等消失,因爲默認文本顏色是白色..所以請告訴我如何將文本顏色更改爲黑色?我試過風格,但它不會工作。

  2. 我檢查的位置存在一些問題。如果檢查的項目之一,以後如果我不加以控制,它仍然顯示該項目被選中,即使它沒有被選中..

這裏是我選中的項目選擇代碼

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

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

}

回答

0

最後我知道你不能用標準ArrayAdapter<String>來改變多選listview的文本顏色。所以我去定製適配器實現。 This鏈接有助於我開發具有多選項實現的自定義適配器。

0

這是一個示例代碼,你可以爲你的

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); 

    } 
} 

main.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"改變文本的顏色。

+0

更改顏色作爲您的願望 – Aerrow

+0

我已經實施了它..但我需要定製它..仔細閱讀問題 – NullPointerException

+0

在哪裏你改變文本顏色,在XML任何活動? – Aerrow

相關問題