2017-12-23 1 views
1

모든 것이 작동합니다. 즉, 데이터가 Firebase에서 읽히고 FirebaseListAdapter에 표시됩니다. 여기 Android ListView 값에서 행 색상 변경 (선택시 제외)

 int urg = model.getUrgency(); 
     if(urg == 1) v.setBackgroundColor(Color.RED); 

문제는 그것이해야보다 빨간색이 무작위로 색상을 더 행이 문제의 코드입니다. 즉, 내 테스트를 위해서 나는 단지 1 레코드에 urg = 1을 기록했다. 그러나 스크롤 할 때, 1 행 이상이 빨간색으로 바뀐다. 수정하려면 어떻게해야합니까?

private void refreshListView(){ 

    fbAdapter = new FirebaseListAdapter<Post>(this, Post.class,R.layout.post_message, query) { 
     @Override 
     protected void populateView(View v, Post model, int position) { 
      TextView messageText = (TextView)v.findViewById(R.id.message_text); 
      TextView messageTime = (TextView)v.findViewById(R.id.message_time); 

      messageText.setText(model.getMessageText()); 
      messageTime.setText(shortTime.format(model.getPostTimeStamp())); 
      int urg = model.getUrgency(); 
      if(urg == 1) v.setBackgroundColor(Color.RED); 
     } 
    }; 

    mListView.setAdapter(fbAdapter); 
    mListView.requestFocus(); 
} 
+0

문제는 여기에 해결 : https://stackoverflow.com/questions/34706585/android-change-background-color-of-specific-item-of-listview –

답변

1

두 개 이상의 행에 빨간색이 표시되는 이유는 else 블록이 없기 때문입니다. else 블록을 추가하면이 문제가 해결됩니다.

int urg = model.getUrgency(); 
if(urg == 1){ 
    v.setBackgroundColor(Color.RED); 
}else{ 
    v.setBackgroundColor(Color.WHITE); 
} 
+0

@arshad은 - 감사합니다 –