I use the Firebase to develop an android app. and was making a post system. so with these codes, I want to click each items in the Firebase RecyclerView.
and I have changed my codes to making a clickable items.
the change is below.
Before,
@Override
protected void onStart() {
super.onStart();
final Query DBquery = FirebaseDatabase.getInstance().getReference().child("post").orderByChild("count");
FirebaseRecyclerAdapter<Post, PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(
Post.class,
R.layout.post_row,
PostViewHolder.class,
DBquery
mDatabase
) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, Post model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(), model.getImage());
viewHolder.setDate(model.getDate());
}
};
mPostList.setAdapter(firebaseRecyclerAdapter);
}
public static class PostViewHolder extends RecyclerView.ViewHolder {
View mView;
public PostViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = mView.findViewById(R.id.post_title);
post_title.setText(title);
}
public void setDesc(String desc){
TextView post_desc = mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImage(Context ctx, String image){
ImageView post_image = mView.findViewById(R.id.post_image);
Picasso.get().load(image).into(post_image);
}
public void setDate(String date){
TextView post_date = mView.findViewById(R.id.post_date);
post_date.setText(date);
}
}
After,
@Overried
protected void onStart() {
super.onStart();
final Query DBquery = FirebaseDatabase.getInstance().getReference().child("post").orderByChild("count");
FirebaseRecyclerOptions<Post> options = new FirebaseRecyclerOptions.Builder<Post>()
.setQuery(DBquery, Post.class)
.build();
final FirebaseRecyclerAdapter<Post, PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(options) {
@NonNull
@Override
public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_row, parent, false);
return new PostViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull PostViewHolder holder, int position, Post model) {
super.onBindViewHolder(holder, position);
holder.setTitle(model.getTitle());
holder.setDesc(model.getDesc());
holder.setImage(getApplication(), model.getImage());
holder.setDate(model.getDate());
}
};
mPostList.setAdapter(firebaseRecyclerAdapter);
}
public static class PostViewHolder extends RecyclerView.ViewHolder {
View mView;
public PostViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = mView.findViewById(R.id.post_title);
post_title.setText(title);
}
public void setDesc(String desc){
TextView post_desc = mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImage(Context ctx, String image){
ImageView post_image = mView.findViewById(R.id.post_image);
Picasso.get().load(image).into(post_image);
}
public void setDate(String date){
TextView post_date = mView.findViewById(R.id.post_date);
post_date.setText(date);
}
}
But I got this error. and I have no clue for this issues actually.
Build Error Below
Program type already present:
android.arch.lifecycle.LiveData$LifecycleBoundObserver
Message{kind=ERROR, text=Program type already present:
android.arch.lifecycle.LiveData$LifecycleBoundObserver, sources=[Unknown
source file], tool name=Optional.of(D8)}
LogCat Error below
06-01 23:45:06.261 1959-3666/? E/SeTransactionSyncTask: Error retrieving account
java.lang.IllegalStateException: No current tap-and-pay account
at alty.b(:com.google.android.gms@[email protected] (040700-197041431):3)
at alty.a(:com.google.android.gms@[email protected] (040700-197041431):1)
at amnv.a(:com.google.android.gms@[email protected] (040700-197041431):28)
at com.google.android.gms.tapandpay.gcmtask.TapAndPayGcmTaskChimeraService.b(:com.google.android.gms@[email protected] (040700-197041431):1)
at com.google.android.gms.tapandpay.gcmtask.TapAndPayGcmTaskChimeraService.a(:com.google.android.gms@[email protected] (040700-197041431):1)
at com.google.android.gms.tapandpay.phenotype.PhenotypeCommitIntentOperation.onHandleIntent(:com.google.android.gms@[email protected] (040700-197041431):47)
at com.google.android.chimera.IntentOperation.onHandleIntent(:com.google.android.gms@[email protected] (040700-197041431):2)
at dbn.a(:com.google.android.gms@[email protected] (040700-197041431):8)
at nam.a(:com.google.android.gms@[email protected] (040700-197041431):9)
at dbs.run(:com.google.android.gms@[email protected] (040700-197041431):10)
at dbp.run(:com.google.android.gms@[email protected] (040700-197041431):9)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
I face similar issue. But, when I open logcat and choose option (at right corner of the logcat screen) "Show only selected application", error didnot show. It seems that error, for me, have no influence on app, and app is working fine with or without thar error. I use google sheets api for read/write data in app, but paying is not part of aplication.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With