Je suis d'essayer d'implémenter la pagination dans mon application.The notifydatasetchanged() charge seulement un élément plutôt que la nouvelle liste entière de 20 éléments.Si quelqu'un pourrait m'aider à résoudre ce? C'est ainsi que j'initialise ma liste.Android Pagination: Notifydatasetchanged() fonctionne mais pas comment il est censé
public static ArrayList<HashMap<String, String>> artistsData = new ArrayList<>();
Ceci est mon post exécution où je mets la pagination et notifier ensemble de données a changé, montrant un bouton plus pour cela:
protected void onPostExecute(ArrayList<HashMap<String, String>> list) {
super.onPostExecute(list);
if (pd.isShowing()) {
pd.dismiss();
}
if (list != null) {
if (ActiveProductsFragment.page == 1) {
mMostViewedAdapter = new ActiveListAdapter(context, list);
listView.setAdapter(mMostViewedAdapter);
Utils.b = new Button(context);
Utils.b.setText(context.getString(R.string.more));
Utils.b.setTextColor(000000);
Utils.b.setTextColor(context.getResources().getColor(android.R.color.white));
Utils.b.setBackgroundColor(context.getResources().getColor(R.color.text_color));
Utils.b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActiveProductsFragment.page++;
ActiveProductsTask artistTask = new ActiveProductsTask(context, listView);
artistTask.execute();
}
});
listView.addFooterView(Utils.b);
} else {
mMostViewedAdapter = new ActiveListAdapter(context, list);
mMostViewedAdapter.notifyDataSetChanged();
}
} else {
Utils.showToastMessage(context, context.getString(R.string.no_record));
}
}
Et voici le code principal de mon adaptateur.
public ActiveListAdapter(Context context, ArrayList<HashMap<String, String>> data) {
this.context = context;
this.data = data;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
à mMostViewedAdapter Obtenir une exception de pointeur nul. –
si c'est le cas, utilisez le code suivant – RaghavPai
mMostViewedAdapter = new ActiveListAdapter (context, list); listView.setAdapter (mMostViewedAdapter); mMostViewedAdapter.notifyDataSetChanged(); – RaghavPai