这是一个包含函数loadMenu的java文件,当相应的intent打开时,应用程序意外关闭。
dispatch(NavigationActions.navigate({
routeName: ‘LandingPage’, <=== will successfully navigate back to the LandingPage
params: responseBody.data.access_token
}));
这是我的MenuviewHolder类:我刚刚为firebase中的图像创建了一个数据库并将其链接到我的应用程序,但它不显示图像只是背景。
private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder> (Category.class,R.layout.item_menu,MenuViewHolder.class,category) {
@Override
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {
viewHolder.txtMenuname.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage())
.into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void OnClick(View view, int position, boolean isLongClick) {
Toast.makeText(navi.this,""+clickItem.getName(),Toast.LENGTH_SHORT).show();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
};
recycle_menu.setAdapter(adapter);
}
}
适配器代码,使用firebaseUI将图像和名称链接到应用程序
public class MenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtMenuname;
public ImageView imageView;
private ItemClickListener itemClickListener;
public MenuViewHolder(View itemView) {
super(itemView);
txtMenuname = (TextView)itemView.findViewById(R.id.menu_name);
itemView = (ImageView)itemView.findViewById(R.id.menu_image);
itemView.setOnClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener){
this.itemClickListener = itemClickListener;
}
@Override
public void onClick(View view) {
itemClickListener.OnClick(view,getAdapterPosition(),false);
}
答案 0 :(得分:0)
private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder>
adapter = new
FirebaseRecyclerAdapter <Category, MenuViewHolder>
(Category.class,R.layout.item_menu,
MenuViewHolder.class,category) {
@Override
protected void
populateViewHolder(MenuViewHolder viewHolder,
Category model, int position) {
viewHolder.txtMenuname.setText(model.getName());
If (model.getimage() != null){
Picasso.with(getapplicationcontext()).
load (model.getImage())
.into(viewHolder.imageView);}
else {//Toast here}
final Category clickItem = model;
viewHolder.setItemClickListener(new
ItemClickListener() {
@Override
public void OnClick(View view, int position,
boolean isLongClick) {
Toast.makeText(navi.this,""+clickItem.getName(),
Toast.LEN
GTH_SHORT).show();
}
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
}
});
}
};
recycle_menu.setAdapter(adapter);
}