So, I imagine this is pretty easy but I can't quite do it - I'm trying to poplate a ListView with data in an array and like a good little boy, I'm using an ArrayAdapter to populate the Listview within the onCreate method of a ListActivity:
Using java Syntax Highlighting
- ArrayAdapter<String> arAdap;
- public class start extends ListActivity {
- public static ArrayAdapter<String> arAdap;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- String[] mStrings = new String[] { "Menu > Poll Devices" };
- arAdap = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
I have another class, in which I'm using AsyncTask to retrieve data from a WebService. The method onPostExecute, which runs when the AsyncTask is done, contains my data in the form of an ArrayList<String>. It is below:
Using java Syntax Highlighting
- protected void onPostExecute(String[] result) {
- start.arAdap = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
As you can see, I'm trying to set the public ArrayAdapter arAdap from this method in the AsyncTask class. I know there's good data in here because I was previously passing it to a simple TextView in the "start" class.
However, I'm getting errors (I'm sure related to context) because the "this" mentioned in the AsyncTask class is obviously not the same as the "this" in the actual ListView class.
So......how to do context for setting the ListView contents from this seperate class?
Or is there a better way to do it entirely that I totally missed? I'm open at this point. Thanks!


