APIからの値に応じてテキストビューの色を変更する必要があるXML parser.inを使用しています。
APIからは1または-1のいずれかが返されます(私にとっては、1の場合は背景を緑、そうでない場合は赤に変更する必要があることを意味します)。
どうやってやるの。
単純...
TextView yourTextView = (TextView)findViewById(R.id.yourTextView);
int response = responseFromParse(); // your parser logic
if(response == 1){
yourTextView.setBackgroundColor(Color.GREEN);
}else{
yourTextView.setBackgroundColor(Color.RED);
}
TextView text_view =(TextView) findViewById(R.id.textView1);
int returnval= your_returnval();
if(returnval== 1){
text_view.setBackgroundColor(Color.GREEN);
}
else if(returnval== -1){
text_view.setBackgroundColor(Color.RED);
}
戻り値が文字列の場合
TextView txt =(TextView) findViewById(R.id.textView01);
String k;
if(k.contentEquals("1")){
`txt.setBackgroundColor(Color.GREEN);`
}
else{
txt.setBackgroundColor(Color.RED);
}
それは簡単です:
if(API()==1)
textView.setBackgroundColor(R.color.black);
else
textView.setBackgroundColor(R.color.black);
これを試して、
TextView txt= (TextView) findViewById(R.id.textview1);
int val=Integer.parseInt(txt.getText().toString());
if(val==1)
txt.setBackgroundColor(Color.GREEN);
else if(val==-1)
txt.setBackgroundColor(Color.RED);