Ich habe ein Problem konfrontiert. Ich arbeite mit Recyclerview. Ich möchte, dass der Listeneintrag aktualisiert wird Wenn Benutzer nach unten scrollen und wenn sie nach links blättern, ruft das Programm die Funktion zum Löschen von Posts auf. Und wenn Sie nach rechts scrollen, ruft das Programm die Update-Funktion auf. Ich habe die Codes unten geschrieben. Können Sie mir anhand von Beispielen erklären, wie ich das machen kann? Ich habe diese Funktionen geschrieben, aber ich habe versagt.wie zu aktualisieren, zu löschen, ... nach dem Scrollen nach unten, oben, rechts und links in Recyclerview
CustomListAdapterForPostOrga
public class CustomListAdapterForPostOrgan extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Posts> post;
private int visibleThreshold = 5;
private int lastVisibleItem, totalItemCount;
private boolean loading;
private OnLoadMoreListener onLoadMoreListener;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public CustomListAdapterForPostOrgan(Activity activity, List<Posts> post) {
this.activity = activity;
this.post = post;
}
public CustomListAdapterForPostOrgan(List<Posts> post, RecyclerView recyclerView) {
this.post = post;
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView
.getLayoutManager();
recyclerView
.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView,
int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager
.findLastVisibleItemPosition();
if (!loading
&& totalItemCount <= (lastVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
if (onLoadMoreListener != null) {
onLoadMoreListener.onLoadMore();
}
loading = true;
}
}
});
}}
public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
this.onLoadMoreListener = onLoadMoreListener;
}
///////////////////
@Override
public int getCount() {
return post.size();
}
@Override
public Object getItem(int location) {
return post.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_row_organ_news
, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
NetworkImageView thumbNail = (NetworkImageView) convertView
.findViewById(R.id.organ_news__avatar_show_thumbnail);
TextView titr = (TextView) convertView.findViewById(R.id.txt_organ_news_list_organ);
TextView year = (TextView) convertView.findViewById(R.id.txt_date_posts_organ);
TextView fi = (TextView) convertView.findViewById(R.id.txt_cunter_for_organ_posts);
// getting billionaires data for the row
Posts m = post.get(position);
// thumbnail image
thumbNail.setImageUrl(m.getAvatar(), imageLoader);
// Wealth Source
year.setText("Wealth Source: " + String.valueOf(m.getPublish_at()));
titr.setText(String.valueOf(m.getTitle()));
// release year
year.setText(String.valueOf(m.getPublish_at()));
fi.setText(String.valueOf(m.getView_count()));
return convertView;
}
public static class ProgressViewHolder extends RecyclerView.ViewHolder {
public ProgressBar progressBar;
public ProgressViewHolder(View v) {
super(v);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
}
}
in Hauptfunktion:
private void handelpost(final List<Post> posts, Page pages) {
if (pages.getCurrentPage() > 1) {
} else {
recycler_post.setLayoutManager(new LinearLayoutManager(this));
final AdapterRcycelerViewPostOrgan
madapter = new
AdapterRcycelerViewPostOrgan(posts);
recycler_post.setAdapter(madapter);
recycler_post.setItemAnimator(new DefaultItemAnimator());
madapter.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
posts.add(null);
madapter.notifyItemInserted(posts.size() - 1);
handler.postDelayed(new Runnable() {
@Override
public void run() {
// remove progress item
posts.remove(posts.size() - 1);
madapter.notifyItemRemoved(posts.size());
//add items one by one
int start = posts.size();
int end = start + 20;
/* for (int i = start + 1; i <= end; i++) {
studentList.add(new Student("Student " + i, "AndroidStudent" + i + "@gmail.com"));
mAdapter.notifyItemInserted(studentList.size());
}*/
// posts.set()
//or you can add all at once but do not forget to call mAdapter.notifyDataSetChanged();
}
}, 2000);
Toast.makeText(getApplicationContext(),"ok",Toast.LENGTH_LONG).show();
}
});
}
Ich möchte wissen, wie ich auf meiner eigenen Listen dieser Funktion tun können. Bitte hilf mir.