I am working on an app for which I am building a comments list. The idea is that the user can add a comment, and review them in a ListView. The problem is that the text color of the items in the ListView is light grey (hard to read) instead of black, unless the app is re-launched with the list of comments already available. In other words, the text is grey only if the comments are added dynamically. Do you guys know why this happens? My code is as follows:
previousCommentsList = (ListView) findViewById(R.id.previous_comments_list);
commentsArrayList = new ArrayList<String>();
for (Comment comment : DrawView.comments) {
commentsArrayList.add(comment.text);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, commentsArrayList);
previousCommentsList.setAdapter(adapter);
saveCommentButton = (Button) findViewById(R.id.save_comment_button);
saveCommentButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
EditText commentEditText = (EditText) findViewById(R.id.comment_edittext);
// Add the comment
Comment comment = new Comment();
comment.text = commentEditText.getText().toString();
DrawView.comments.add(comment);
Toast.makeText(getApplicationContext(), "Comment saved", Toast.LENGTH_SHORT).show();
commentsArrayList = new ArrayList<String>();
for (Comment comment2 : DrawView.comments) {
commentsArrayList.add(comment2.text);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, commentsArrayList);
previousCommentsList.setAdapter(adapter);
// Probably using both notifyDataSetChanged() and invalidate() is redundant
adapter.notifyDataSetChanged();
previousCommentsList.invalidate();
}
});