-1

APIからの値に応じてテキストビューの色を変更する必要があるXML parser.inを使用しています。

APIからは1または-1のいずれかが返されます(私にとっては、1の場合は背景を緑、そうでない場合は赤に変更する必要があることを意味します)。

どうやってやるの。

4

5 に答える 5

3

単純...

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);    
}
于 2012-05-08T06:12:48.917 に答える
0

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);    
}
于 2012-05-08T06:25:09.607 に答える
0

戻り値が文字列の場合

TextView txt =(TextView) findViewById(R.id.textView01);

String k;

if(k.contentEquals("1")){

 `txt.setBackgroundColor(Color.GREEN);`

}

else{

txt.setBackgroundColor(Color.RED);

}

于 2012-05-08T06:15:20.360 に答える
0

それは簡単です:

if(API()==1)
    textView.setBackgroundColor(R.color.black);
else
    textView.setBackgroundColor(R.color.black);
于 2012-05-08T06:14:19.610 に答える
0

これを試して、

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);
于 2012-05-08T06:18:19.237 に答える