안드로이드에서 listview 사용하여 안에 item넣었는데 메인은 다른xml참조 중인데
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_dash_board, null);
}
listview안에있는 item(dash_ntr_item.xml) 색상변경을 어떻게 하죠 ㅠㅠ
아래 부분 주석처리한것처럼 하고싶은데 참조된 xml은 다른거라안되네요,,,,
if(delay.equals(delay2)){
sw = "ON";
// color_delay.setTextColor(Color.YELLOW);
}else if(delay.equals("0")){
sw = "ERROR";
// color_delay.setTextColor(Color.RED);
}else{
sw="OFF";
// color_delay.setTextColor(Color.GRAY);
}
public void ntrService(){
Response.Listener<String> responseListener = new Response.Listener<String>() {
String lighton,sw ;
@Override
public void onResponse(String response) {
try{
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("service");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject c = jsonArray.getJSONObject(i);
String name = c.getString("name");
String temp = c.getString("temp");
String delay = c.getString("delay");
String delay2 = c.getString("delay2");
String light = c.getString("light");
String temp2 = c.getString("temp2");
String temp3 = c.getString("temp3");
String temp4 = c.getString("temp4");
if (!(name.equals("-"))) {
if(light.equals("1")){
lighton ="ON";
}else{
lighton ="OFF";
}
if(delay.equals(delay2)){
sw = "ON";
// color_delay.setTextColor(Color.YELLOW);
}else if(delay.equals("0")){
sw = "ERROR";
// color_delay.setTextColor(Color.RED);
}else{
sw="OFF";
// color_delay.setTextColor(Color.GRAY);
}
//해시맵에 데이터 추가
HashMap<String, String> ntrname = new HashMap<String, String>();
ntrname.put("name", name);
ntrname.put("temp", temp+"℃");
ntrname.put("delay2",sw);
ntrname.put("delay", "("+delay+"분)");
ntrname.put("temp2", temp2);
ntrname.put("temp3", temp3);
ntrname.put("temp4", temp4);
ntrList.add(ntrname);
}
}
//adapter이용하여 list에 값넣기
ListAdapter adapter = new SimpleAdapter(
getContext(), ntrList, R.layout.dash_ntr_item,
new String[]{"name","temp","delay2","delay","temp2","temp3","temp4"},
new int[]{R.id.name,R.id.temp,R.id.delay2,R.id.delay,R.id.temp2,R.id.temp3,R.id.temp4}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
};
DashNtr dashNtr = new DashNtr(mb_id, responseListener);
RequestQueue queue = Volley.newRequestQueue(getContext());
queue.add(dashNtr);
}