Я пытаюсь использовать Пикассо для загрузки фрагмента изображения и просмотра Recycler. Но я не могу загрузить картинку. Первоначально я думал, что, возможно, он не может получить URL-адрес из БД, но в результате отладки я увидел правильный URL-адрес. Я пробовал жестко закодированный URL, но он все еще не работает. Надеюсь, что эксперты могут помочь мне.
Это код:
public class MenuFragment extends Fragment {
private MenuViewModel menuViewModel;
FirebaseDatabase database;
DatabaseReference category;
RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
//init fireabse
database = FirebaseDatabase.getInstance();
category = database.getReference("Category");
View root = inflater.inflate(R.layout.fragment_memu, container, false);
recycler_menu = (RecyclerView) root.findViewById(R.id.recycler_menu);
recycler_menu.setHasFixedSize(true);
recycler_menu.setLayoutManager(new LinearLayoutManager(inflater.getContext()));
loadMenu();
//recycler_menu.setAdapter(new ChatRecyclerViewAdapter());
return root;
}
private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(
Category.class, R.layout.menu_item, MenuViewHolder.class, category) {
@Override
protected void populateViewHolder(MenuViewHolder viewHolder, Category category, int i) {
viewHolder.txtMenuName.setText(category.getName());
Picasso.with(getContext()).load("https://www.wikihow.com/Get-the-URL-for-Pictures#/Image:Get-the-URL-for-Pictures-Step-6-Version-3.jpg").
fit().centerCrop().into(viewHolder.imageView);
final Category clickItem = category;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View v, int position, boolean isLongClick) {
Toast.makeText(getActivity().getBaseContext(),""+clickItem.getName(),Toast.LENGTH_SHORT).show();
}
});
}
};
recycler_menu.setAdapter((adapter));
}
}
Это XML часть
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.menu.MenuFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>