Using an adapter from another class/activity
<p>How can I use an ArrayAdapter from another activity? I tried doing the following in MyListActivity.onCreate():</p>

<pre><code>setListAdapter(SomeOtherActivity.myAdapter);
</code></pre>

<p>where myAdapter is defined and initialized in SomeOtherActivity. However, I get an empty list, even though I verified that SomeOtherActivity.myAdapter is fully populated via a call to:</p>

<pre><code>SomeOtherActivity.myAdapter.getCount();
</code></pre>

<p>If I define and initialize my own adapter in MyListActivity with setListAdapter(myLocalAdapter), it works. Once I switch it to setListAdapter(SomeOtherActivity.myAdapter), I get an empty list. I debugged it and found that the adapter's getView() isn't even called.</p>

<p>Help please? Thanks.</p>

<p>In MainActivity.onCreate()</p>

<pre><code>listIsDone = false;
myList = new ArrayList&lt;ItemInfo&gt;();
init = new Runnable() {
  public void run() {
    myList = generate(); // generate the list, takes a while
    Collections.sort(myList, new CustomComparator()); // sorts the list
    myAdapter = new MyInfoAdapter(MainActivity.this, R.layout.row, myList);
    synchronized(this) {
      listIsDone = true;
      notifyAll();
    }
  }
};
Thread thread = new Thread(null, init, "Background");
thread.start;
</code></pre>

<p>In my SubActivity.onCreate()</p>

<pre><code>setListAdapter(MainActivity.myAdapter);
doStuff = new Runnable() {
  public void run() {
    synchronized(MainActivity.init) {
      if (!MainActivity.getListDone()) {
        try {
          MainActivity.init.wait(); // wait for list/adapter to be initialized
        } catch (InterruptedException e) {
        }
      }
    }
  }
};
Thread thread = new Thread(null, doStuff, "Background");
thread.start();
</code></pre>

<p>I notice I can't run myAdapter.notifyDataSetChanged() in a Runnable thread(I get a runtime error), but I can do it in a runnable if I run it with runOnUiThread(); I'm guessing all method calls to the adapter needs to be done in the same UI thread?</p>
