Whats wrong in this code..
public class MoviesListActivity extends ListActivity {
private ArrayList<Movie> moviesList;
private ArrayAdapter<Movie> moviesAdapter;
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.movies_layout);
moviesList = (ArrayList<Movie>) getIntent().getSerializableExtra("movies");
moviesAdapter = new MoviesAdapter(this, R.layout.movie_data_row, moviesList);
setListAdapter(moviesAdapter);
if (moviesList!=null && !moviesList.isEmpty()) {
longToast(String.valueOf(moviesList.size()));
moviesAdapter.clear();
moviesAdapter.notifyDataSetChanged();
for (int i = 0; i < moviesList.size(); i++) {
moviesAdapter.add(moviesList.get(i));
}
}
moviesAdapter.notifyDataSetChanged();
}
after moviesAdapter.clear();
, moviesList.size()
become zero. and before clear code movieslist get some data. Now after removing moviesAdapter.clear()
, application get force close... Pls help..Thanks
moviesAdapter.clear()
operates upon. I'm having a hunch that yourMoviesAdapter
might be directly referencing yourmoviesList
, and therefore the clear is directly affecting yourmoviesList
. I'm wondering though, why you're not first setting the data in the adapter before callingsetListAdapter
. Then you wouldn't need 2 moviesAdapter.notifyDataSetChanged calls. – Xilconic Jun 24 at 6:19