我尝试使用firebase在我的应用中显示,但不返回图像或其他数据请帮助我我在没有任何错误之后使用它,但现在我不使用此方法
public class PaylasAnaSayfa extends AppCompatActivity {
private RecyclerView mBlogList;
public DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paylas_ana_sayfa);
mDatabase= FirebaseDatabase.getInstance().getReference().child("Resimler");
mBlogList= (RecyclerView) findViewById(R.id.resim_list);
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(new LinearLayoutManager(this));
if (mDatabase==null){
Toast.makeText(this, "veri tabanı hatası", Toast.LENGTH_SHORT).show();
}else {
FirebaseRecyclerAdapter<PaylasModel, PaylasHolder> adapter = new FirebaseRecyclerAdapter<PaylasModel, PaylasHolder>(
PaylasModel.class,
R.layout.resim_row,
PaylasHolder.class,
mDatabase
) {
@Override
protected void populateViewHolder(PaylasHolder viewHolder, PaylasModel model, int position) {
viewHolder.setImage(getApplicationContext(), model.getImgImage());
viewHolder.setBaslik(model.getImgBaslik());
viewHolder.setAciklama(model.getImgAciklama());
viewHolder.setKullanici(model.getImgKullaniciAdi());
viewHolder.setDers(model.getImgDers());
}
};
mBlogList.setAdapter(adapter);
}
}
private static class PaylasHolder extends RecyclerView.ViewHolder {
View mView;
public PaylasHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setBaslik(String baslik){
TextView tBaslik= (TextView) mView.findViewById(R.id.row_img_baslik);
tBaslik.setText(baslik);
}
public void setAciklama(String aciklama){
TextView tAciklama= (TextView) mView.findViewById(R.id.row_img_aciklama);
tAciklama.setText(aciklama);
}
public void setKullanici(String kullanici){
TextView tKullanici= (TextView) mView.findViewById(R.id.row_img_kullanici);
tKullanici.setText(kullanici);
}
public void setDers(String ders){
TextView tDers= (TextView) mView.findViewById(R.id.row_img_ders);
tDers.setText(ders);
}
public void setImage(final Context context, final String image){
final ImageView tImage= (ImageView) mView.findViewById(R.id.row_img_image);
Picasso.with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(tImage, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(context).load(image).into(tImage);
}
});
}
}
}
使用视图持有人不要返回数据方括号中的单词是Alt文本,如果浏览器无法显示图像,则会显示出它。确保包含用于屏幕阅读软件的有意义的Alt文本。
首先,您不需要在视图持有人的方法中每次初始化视图。recyClerview。
private static class PaylasHolder extends RecyclerView.ViewHolder {
View mView;
TextView tBaslik;
public PaylasHolder(View itemView) {
super(itemView);
mView=itemView;
tBaslik = mView.findViewById(R.id.row_img_baslik);
//intialize all you view here once and for all.
}
public void setBaslik(String baslik){
tBaslik.setText(baslik);
}
public void setAciklama(String aciklama){
tAciklama.setText(aciklama);
}
public void setKullanici(String kullanici){
tKullanici.setText(kullanici);
}
public void setDers(String ders){
tDers.setText(ders);
}
public void setImage(final Context context, final String image){
Picasso.with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(tImage, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(context).load(image).into(tImage);
}
});
}
}
如果您非常确定RecyClerview的大小,则仅使用sethasfixedsize(true),否则,在将数据添加到适配器中时不会请求布局。