0

I have defined a ListView, tha gets the data from a service, it has an empty view too:

public class MyActivity extends Activity {

MyObject myObject;
ListView myListView;
MyAdapter myAdapter;
ArrayList<MyListElement> myElements;

Handler h = new Handler(){
   public void handleMessage (Message msg){
      if(msg.what == 0){
          init((ArrayList<MyListElement> ))
      }
   }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.my_layout);
    myListView = (ListView) findViewById(R.id.my_listview);

    myObject = (myObject) getIntent().getExtras().get("myObj");
    setTitle(getString(R.string.title_activity_chat) + myObject.getDisplayedName());

    myElements = new ArrayList<MyListElement>();
    LayoutInflater inflater = getLayoutInflater();
    myAdapter = new MyAdapter(this, this, R.layout.my_activity, myElements);
    myListView.setEmptyView(findViewById(R.id.text1));
    myListView.setAdapter(myAdapter);
    Intent i = new Intent(MyActivity.this, MyService.class);
            ...
    startService(i);
}

protected void init(List<MyListElement> pHistory) {
    myAdapter.addAll(pHistory);
    myAdapter.notifyDataSetChanged()
}
...
}

and I have an own ArrayAdapter (MyAdapter).

My problem is, when I start the activity and call the service after I get back the data to init(...) the UI refreshes itself with black flash.

Did somebody met this problem?

kisstajmi
  • 255
  • 2
  • 12
  • Without reading your code, check this out: http://stackoverflow.com/questions/2833057/background-listview-becomes-black-when-scrolling – VM4 Dec 12 '13 at 13:46
  • It is not a scrolling problem, after the init I can do everything with the data, clear or add +n rows, just the first (starter) event makes this behavior. – kisstajmi Dec 12 '13 at 15:12

1 Answers1

0

I have solved the problem permanantly with this code:

myAdapter.add(first);
myListView.post(new Runnable() {
    @Override
    public void run() {
        while (myListView.getWidth() == 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        myAdapter.remove(first);
    }
});
kisstajmi
  • 255
  • 2
  • 12