내 응용 프로그램에서 페이징을 구현하려고합니다. notifydatasetchanged()는 20 개 요소의 전체 목록 대신 하나의 항목 만로드합니다. 누군가가 나를 도울 수 있다면 이? 이것은 내 목록을 초기화하는 방법입니다.안드로이드 페이지 매기기 : Notifydatasetchanged() 작동 방식은 아니지만
public static ArrayList<HashMap<String, String>> artistsData = new ArrayList<>();
내 게시물이에 대한 더 버튼을 보여주는 데이터 세트가 변경 내가 매김을 설정할 경우 실행 및 통지 않습니다 :
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));
}
}
는 그리고 이것은 내 어댑터의 주요 코드입니다. 그나마 다른 부분에 대한
artistsData.clear();
artistsData.addAll(list);
mMostViewedAdapter.notifyDataSetChanged();
다음과 같이 동일한 어댑터 사용의 새 인스턴스를 만들
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;
}
을 실행 게시물에이 일을. –
이면 다음 코드를 사용하십시오. – RaghavPai
mMostViewedAdapter = new ActiveListAdapter (context, list); listView.setAdapter (mMostViewedAdapter); mMostViewedAdapter.notifyDataSetChanged(); – RaghavPai