I want to change the background of a TextView, which is inserted in a ListView. The ListView contains a series of TextView, and the value of each one is retrieved from a simple List. Now I show you my snippet:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.town_selection);
list = (ListView) findViewById(R.id.list);
adapter = new ArrayAdapter<>(this, R.layout.string_item, App.towns);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
adapter.notifyDataSetChanged();
list.invalidate();
// list.getCount() returns zero!!
// and so, list.getChildAt(...) returns null!!
}
App.towns is the list of String I was talking, and its length is greater than 0. When the app is running it seems ok, because the ListView is showing the items, but at the end of the onCreate I need to change the background color of some items, but the ListView seems not ready as I commented.
notifyDataSetChanged() and invalidate() doesn't help.