2012-05-08 13 views
-1

XML 파서를 사용하여 API에서 오는 값에 따라 텍스트 뷰의 색상을 변경해야합니다.텍스트 뷰의 색상 변경

api에서 1 또는 -1을 반환합니다 (1이면 녹색 대신 배경색을 변경해야 함).

어떻게 할 수 있습니까? 간단한

답변

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);  
} 
+0

감사 Rashmi.I는 해시 맵 1로 동일 또는 그렇소이 시도로부터한다는 점에서 어떻게 가치있는을 확인할 수 있습니다, 내가 해시 맵의 API에서 가져온 값을 저장하고 내 경우 doubt.In 하나 더있다 if (map.get (KEY_DIRECTION) .contains ("1"))하지만 작동하지 않습니다. – subburaj

+0

은 Hashmap이 또는 입니까? – NullPointerException

+0

subburaj

0

그것은 쉽게 다음 returm 값이 문자열에

if(API()==1) 
    textView.setBackgroundColor(R.color.black); 
else 
    textView.setBackgroundColor(R.color.black); 
0

경우 시도

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

String k;

,

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

`txt.setBackgroundColor(Color.GREEN);` 

}

else{

txt.setBackgroundColor(Color.RED); 

}

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); 
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);  
}