我正在尝试从用户的奖励中填充嵌套子视图,但是我无法在Android App上显示任何内容。关于如何进行的任何建议?请参阅以下有关我到目前为止已编码的代码。
我的模特
public class myrewards{
String barImg;
public myrewards()
{
}
public myrewards(String barImg) {
this.barImg = barImg;
}
public String getBarImg() {
return barImg;
}
public void setBarImg(String barImg) {
this.barImg = barImg;
}
}
我的观看者
public class RewardViewHolder extends RecyclerView.ViewHolder{
View mView;
public RewardViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setRewardDetail(Context ctx, String barImg)
{
ImageView rImg = mView.findViewById(R.id.rImage);
Picasso.with(ctx).load(barImg).into(rImg);
}
}
我的主要活动
public class MyRewardsActivity extends AppCompatActivity {
private static final String TAG = MyRewardsActivity.class.getSimpleName();
private RecyclerView rRecycleView;
private DatabaseReference myReward, userRef, voucherRef;
private FirebaseAuth mAuth;
private String userID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_rewards);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("My Rewards");
rRecycleView = findViewById(R.id.my_reward);
rRecycleView.setHasFixedSize(true);
rRecycleView.setLayoutManager(new LinearLayoutManager(this));
mAuth = FirebaseAuth.getInstance();
userID = mAuth.getCurrentUser().getUid();
myReward = FirebaseDatabase.getInstance().getReference().child("User").child(userID);
userRef = FirebaseDatabase.getInstance().getReference().child("User").child(userID);
System.out.println("YOUR REWARD= " + myReward);
}
@Override
protected void onStart() {
super.onStart();
final FirebaseRecyclerAdapter<myrewards, RewardViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<myrewards, RewardViewHolder>
(
myrewards.class,
R.layout.barrewards,
RewardViewHolder.class,
myReward
)
{
@Override
protected void populateViewHolder(RewardViewHolder viewHolder, myrewards model, int position) {
viewHolder.setRewardDetail(getApplicationContext() ,model.getBarImg());
}
};
rRecycleView.setAdapter(firebaseRecyclerAdapter);
}
}
下图所示:
我不确定我是否使用了正确的编码方式,就像我一直在使用这种方式从数据库中检索其他数据(不是嵌套子级)一样,是否真的有任何帮助并在此先感谢您。