2017-09-27 17 views
0

私が持って次のようにKartheek(ありがとうございます)によって答えと試験に適合しChange the color of a specified item in a listview for androidと同じ問題:Androidの変更のTextViewフォントの色

adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){ 
     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
{ 
      View view1 = super.getView(position, convertView, parent); 
//   if (position % 2 == 0) { //Place the condition where you want 
to change the item color. 
     testo = messaggi.get(position); 
      if(testo.substring(0,5).equals("27-09")){ 
      view1.setBackgroundColor(Color.parseColor("#e0e0ef")); 
     } else { 
      //Setting to default color. 
      view1.setBackgroundColor(Color.WHITE); 
     } 
     return view1; 
     } 
    }; 

が質問:私はむしろ、フォントの色を変更しかし、view1.setTextColor(Color.parseColor( "#E0E0EF");)は動作していないようです;

+0

書き込みconvertViewと交換しているというレイアウトでこのレイアウト.setBackgroundColor(Color.parseColor( "#e0e0ef")); – Ankita

+0

あなたのdb_msgレイアウトのXMLコードが含まれています – SiSa

+0

私たちにこのレイアウトを見せてください。R.layout.db_msg –

答えて

0

表示会社db_msg 1つのTextViewがまさにそれの名前を取得し、「tvIDFrom_db_msg_layout」この

adapter = new ArrayAdapter<String>(this,R.layout.db_msg,messaggi){ 
     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
    { 
      View view1 = super.getView(position, convertView, parent); 
     if (position % 2 == 0) { //Place the condition where you want to change the item color. 
      testo = messaggi.get(position); 
       TextView tvText = (TextView) view1.findViewById(R.id.tvIDFrom_db_msg_layout); 
      if(testo.substring(0,5).equals("27-09")){ 

       tvText.setTextColor(Color.parseColor("#yourHexCode")); 
      } else { 
       //Setting to default color. 
       tvText.setTextColor(Color.WHITE); 
      } 
     return view1; 
     } 
    }; 
+0

はい、動作します!tvText.setTextColor(Color.parseColor(" #0000ef ")); – alberto

0

あなたのコマンドで最後に ')'が間違っているようです。それ以外の場合は、正しい縫い目:

view1.setTextColor(Color.parseColor("#E0E0EF")); 
0
@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View view1; 
view1=convertView; 
if (convertView == null) { 
     view1 = inflater.inflate(R.layout.db_msg, null); 
     testo = messaggi.get(position); 
     if(testo.substring(0,5).equals("27-09")){ 
     view1.setBackgroundColor(Color.parseColor("#e0e0ef")); 
    } 
else { 
     //Setting to default color. 
     view1.setBackgroundColor(Color.WHITE); 
    } 
     return convertView; 
} 
関連する問題