2014-04-23 25 views
0

如果記錄註釋和空 保持白色,而TextView如果不是紅色,我該怎麼做? 我試了,但我不工作,下面的代碼如果記錄不爲空,如何更改顏色texview?

String notes = notesName.get(pos); 
if (notes != null) { 
    mHolder.txt_notes.setTextColor(Color.WHITE); 
} else { 
    mHolder.txt_notes.setTextColor(Color.RED); 
} 

回答

0
String Notes = notesName.get(pos); 
    if (Notes.length() != 0){ 
     mHolder.txt_notes.setBackgroundColor(Color.WHITE); 
    } else{ 
     mHolder.txt_notes.setBackgroundColor(Color.RED);} 
+0

好吧,它的工作原理,謝謝 – user3564888

0

嘗試: -

mHolder.txt_notes.setBackgroundColor(Color.YELLOW); 

mHolder.txt_notes.setBackgroundColor(getResources().getColor(R.color.darkgrey)); 
0
String Notes = notesName.get(pos); 
     if (Notes != null && !Notes.isEmpty()) 
         mHolder.txt_notes.setBackgroundColor(Color.WHITE); 
        else 
        mHolder.txt_notes.setBackgroundColor(Color.RED); 
+0

如果我把:如果(注意!= null &&! Notes.isEmpty()), 是錯誤的。 – user3564888

+0

我很抱歉,但它似乎工作正常,我注意到,當我滾動列表視圖,即使沒有什麼在Notes中,我texview其他顏色在列表視圖中,顯然是錯誤的, 如果您重新啓動顯示適配器恢復操作 看來,隨着大膽需要刷新 – user3564888

0
String Notes = notesName.get(pos); 
    if (!Notes.equalsIgnoreCase("")){ 
        mHolder.txt_notes.setBackgroundColor(Color.WHITE); 
       } else 
       mHolder.txt_notes.setBackgroundColor(Color.RED);