0
Hello, I’m new to Recyclerview, I’m trying to create an Adapter for it, but when I define an Adapter for Recyclerview, the crash app, someone knows why?
Mainactivity
/...
RecyclerView recyclerView = findViewById(R.id.recycler_view);
RecyclerView.LayoutManager recyclerManager;
ArrayList<String> listDrawer = new ArrayList<>();
listDrawer.add("Teste");
recyclerView.setHasFixedSize(true);
recyclerManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(recyclerManager);
//Agora quando defino a Adapter, o app crasha
recyclerView.setAdapter(new RecyclerAdapter(listDrawer));
/...
Recycleradapter
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.DataObjectHolder> {
private ArrayList<String> data;
public class DataObjectHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public DataObjectHolder(View itemView) {
super(itemView);
}
@Override
public void onClick(View v) {
}
}
public RecyclerAdapter(ArrayList<String> data) {
this.data = data;
}
@Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.main_nav_files_items, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
}
@Override
public int getItemCount() {
return data.size();
}
}