I know this question has been asked several times, but the solutions have been specific to the askers' problems. Consequently, none of those solutions helped me, even though I tried following all of their suggestions.
So here goes.
I have a movies Activity like this. Notice that I have a MoviesAdapter
inner class, that's supposed to populate the moviesDisplay
ListView
.
package com.example.midtermexam;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.database.DataSetObserver;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class MoviesActivity extends Activity {
public String url;
public ListView moviesDisplay;
public static ArrayList<Movie> thisMovies;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movies);
url=getIntent().getExtras().getString("url");
moviesDisplay = (ListView)findViewById(R.id.listView1);
new AsyncMoviesGet(this).execute(url);
}
public void populateListView()
{
Log.d("listview","adapter created");
Log.d("listview","Listview declared");
Log.d("listview","adapter populated");
moviesDisplay.setAdapter(new MoviesListAdapter());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.movies, menu);
return true;
}
private class MoviesListAdapter extends ArrayAdapter<Movie> {
public MoviesListAdapter() {
super(MoviesActivity.this, R.layout.movies_activity_listview, thisMovies);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Make sure we have a view to work with (may have been given null)
View movieView = convertView;
if (movieView == null) {
movieView = getLayoutInflater().inflate(R.layout.movies_activity_listview, parent, false);
}
// Find the car to work with.
return movieView;
}
}
}
The populateListView() method is called from an AsyncTask called AsyncMoviesGet, whose postExecute() looks like this.
@Override
protected void onPostExecute(ArrayList<Movie> result) {
if(result != null){
m.thisMovies = result;
m.populateListView();
Log.d("demo", result.toString());
} else{
Log.d("demo", "null result");
}
}
You can see the Log messages inside the populateListView()
method. These 3 statements get executed. However, the setAdapter()
function doesn't seem to call the "GetView
" function.