'Recyleview No Adapter attached; skipping layout error [duplicate]
Trying to implement recyclerview into my project that has bottom navigation bar that has 3 item and each item has its each fragment.
But I keep getting error No adapter attached, skipping layout error.
This is my adapter
public class CategoryAdapter extends BaseAdapter {
private List<CategoryModel> cat_list;
public CategoryAdapter(List<CategoryModel> cat_list) {
this.cat_list = cat_list;
}
@Override
public int getCount() {
return cat_list.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
public View getView(int i, View view, ViewGroup viewGroup) {
View myView;
if (view == null){
myView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cat_item_layout,viewGroup,false);
}else {
myView = view;
}
TextView catName = myView.findViewById(R.id.catName);
TextView noOfQuestion = myView.findViewById(R.id.no_of_questions);
catName.setText(cat_list.get(i).getName());
noOfQuestion.setText(String.valueOf(cat_list.get(i).getNoofquestions()) + " question");
return myView;
}
This is the main activity
bottomNavigationView = findViewById(R.id.fragment_bottom_navigation_menu_mahasiswa);
container_frame_mahasiswa = findViewById(R.id.container_frame_mahasiswa);
//bottomNavigationView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener);
RecyclerView recyclerView = findViewById(R.id.mahasiswa_RecycleView);
//catView = v.findViewById(R.id.cat_Grid);
//adapter = new CategoryAdapter(categoryModels);
//adapter = new CategoryAdapter(categoryModels);
//recyclerView.setAdapter(adapter);
//recyclerView.setLayoutManager(new LinearLayoutManager(this));
//recyclerView.setAdapter(RecyclerView.Adapter);
as you can see I've tried a lot of stuff but it just wouldnt work
Solution 1:[1]
Try implementing your adapter like this
public class MyAdapter extends RecyclerView.Adapter<MyListAdapter.ViewHolder>{
private List<model> listdata;
// RecyclerView recyclerView;
public MyAdapter(List<model> listdata) {
this.listdata = listdata;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View listItem= layoutInflater.inflate(R.layout.list_item, parent, false);
ViewHolder viewHolder = new ViewHolder(listItem);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return listdata.length;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
}
}
}
And Implement your code in Activity like this
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
MyAdapter adapter = new MyAdapter(myListData);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
In your viewHolder you should initialize your views like this
public static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
public TextView textView;
public ViewHolder(View itemView) {
super(itemView);
this.imageView = (ImageView) itemView.findViewById(R.id.imageView);
this.textView = (TextView) itemView.findViewById(R.id.textView);
}
}
Solution 2:[2]
Assuming we are in the Z plane with two walls, the ball would bounce right back as we have two reflections with a 45° incidence angle causing a movement change of +90° respectively.
A 'direct hit' would just result in the brown arrow being infinitely short.
This applies in dimension of you treat a corner as the conjunction point of N perpendicular walls.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tariq Hussain |
| Solution 2 | Beltway |

