2013-04-02 42 views
-1
ListAdapter adapter = new SimpleAdapter(this, menuItems, 
       R.layout.recentlist, 
       new String[] { CAT, DATE, TID, AMO, DEB,CUR,BAL,FEES}, new int[] { 
       R.id.textView1,R.id.textView2, R.id.textView3, R.id.textView4,R.id.textView5,R.id.textView7,R.id.textView6,R.id.textView8}); 

     DEB.setTextColor(Color.RED); 



     setListAdapter(adapter); 

我想設置顏色DEB或textView5.But我得到這個錯誤。更改textView顏色使用if if條件

的方法setTextColor(INT)是不確定的String類型

我也曾嘗試使用

    R.id.textView5.setTextColor(Color.RED) 

但這個錯誤就

不能調用的基本類型setTextColor(INT) int

請幫我解決這個問題。

+0

你可以做到這一點的TextView TV =(TextView的)findViewByID(R.id.textView5); tv.setTextColor(Color.RED); –

回答

2

至於你的第二次嘗試,R.id.textView5是對你的TextView的引用。爲了得到對象本身,使用findViewById方法:

((TextView)findViewById(R.id.textView5)).setTextColor(Color.RED); 

(假設R.id.textView5的確是TextView一個實例)。

+0

我不能這樣做,因爲它會選擇其他xml文件的textView id。此xml佈局僅適用於listview。 –

0

使用下面的代碼。

TextView textView5 = (TextView)findViewById(R.id.textView5); 

textView5.setTextColor(R.color.RED); 
+0

我不能這樣做,因爲它會選擇其他xml文件的textView id。此xml佈局僅適用於listview。 –

+0

你試過了嗎? –

+0

是的,我已經嘗試過 –

1

你必須創建TextView的對象

試試這個

TextView textView5 = (TextView)findViewById(R.id.textView5); 

textView5.setTextColor(getResources().getColor(R.color.red));