I have completed my app but in this, I want to show data by date wise. How it possible?
This is my database Structure.
This is my Recycler Adapter
public class BscRecyclerAdapter extends
RecyclerView.Adapter<BscRecyclerAdapter.ViewHolder> {
private List<MainPage> mMainPage;
private Context context;
public BscRecyclerAdapter(Context context,List<MainPage> mMainPage){
this.context = context;
this.mMainPage =mMainPage;
}
@Override
public BscRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
return new ViewHolder(view); }
@Override
public void onBindViewHolder(BscRecyclerAdapter.ViewHolder holder, final int position) {
holder.mTitle.setText(mMainPage.get(position).getTitle());
holder.mDescription.setText(mMainPage.get(position).getDescription());
holder.mDate.setText(mMainPage.get(position).getDate());
final String Title = mMainPage.get(position).getTitle();
final String Description = mMainPage.get(position).getDescription();
final String Image = mMainPage.get(position).getImage();
final String Date = mMainPage.get(position).getDate();
final String main_id = mMainPage.get(position).mainId;
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent UpdateIntent = new Intent(context,BscUpdateDelete.class);
UpdateIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UpdateIntent.putExtra("main_id",main_id);
UpdateIntent.putExtra("title",Title);
UpdateIntent.putExtra("description",Description);
UpdateIntent.putExtra("date",Date);
UpdateIntent.putExtra("image",Image);
context.startActivity(UpdateIntent);
}
});
holder.mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = mMainPage.get(position).getImage();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url));
context.startActivity(intent);
}
});
ImageView post_image = holder.mImage;
Glide.with(context).load(mMainPage.get(position).getImage()).into(post_image);
}
@Override
public int getItemCount() {
return mMainPage.size();
}
I have searched on Google many Times but I not got any solution Please Help. what I do in my recycleradpter for showing data datewise.
This is my Fragment. I have used order by date but in this post showing by date but when month changed
like today date is
25-07-2018
26-07-2018
27-07-2018
28-07-2018
and then when I created a new post of date 27-06-2018.
its show me this post after 26-07-2018.
mFirestore.collection("Bsc").orderBy("date").addSnapshotListener(new
EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
for (DocumentChange doc: documentSnapshots.getDocumentChanges()){
if (doc.getType() == DocumentChange.Type.ADDED){
String doc_id = doc.getDocument().getId();
MainPage mainPage = doc.getDocument().toObject(MainPage.class).witId(doc_id);
mMainPage.add(mainPage);
mainPageRecyclerAdapter.notifyDataSetChanged();
}
}
}
});