I have got one activity, but 3 layouts. ListView is a part of layout that is being displayed after loging in. That's why I can't set my ArrayAdapter onCreate, bacause my ListView is not initialized yet. I tried following this tutorial, but I could not reproduce these steps. In this tutorial author did everything onCreate.
I tried doing it this way:
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
...
public class getcontacts extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
...HERE I AM FETCHING DATA...
listItems.add(json_data.getString("login") + " " + derp);
}
@Override
protected void onPostExecute(final Boolean success) {
getc = null;
ac = new addcontacts();
ac.execute(true);
And here is the code of addcontacts class:
public class addcontacts extends ListActivity {
protected void onCreate() {
adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
adapter.notifyDataSetChanged();
}
protected void execute(final Boolean success) {
done = true;
}
}
And the layout:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="188dp"
android:layout_weight="0.53"
android:text="Fetching contact list" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="106dp" >
</ListView>
</LinearLayout>
ListView doesn't contain anything. I checked in debugger that listItems have all items, so there is something wrong with adapter.
onCreate()needs to get a Bundle as an argument. Use@Overrideannotations, it will make like easier. Also, please use proper naming conventions and show us how each class is set up. If both the AsyncTask and the ListActivity are part of the same file, don't separate them.