0
Error: RecyclerView﹕ No adapter attached; skipping layout
I saw several items really similar to this error here, but none solved my problem. The list is loaded normally, only after adding the interface, which I created, to click on an item in the list (this click interface is used in other situations, usually), is that the error occurs. And recyclerview is created in alertDialog.
I tried to change the position of the code as I saw that the list might not be filled in or the Adapter not loaded yet, but it didn’t work.
After going to the server, return a list of items and only after this return, create the items related to recyclerview and Adapter. Working with asyncTask, this returns to Activity via a method that is overwritten.
follows the codes
Activity/dialog:
public void buildDialogToPredicted(String whichDialog) {
//método criado, após o retorno para a criação do dialog com a lista de itens preditos.
startVoiceWave(this, this);
View viewAlertDialog = LayoutInflater.from(this).inflate(R.layout.predict_layout, null);
recyclerView = viewAlertDialog.findViewById(R.id.recycler_predict);
recyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(mLayoutManager);
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setView(viewAlertDialog)
.setCancelable(true);
final AlertDialog dialog1 = dialog.create();
Button close = viewAlertDialog.findViewById(R.id.btn_close_predic);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
vpPager.setCurrentItem(vpPager.getCurrentItem() + 1, true);
dialog1.dismiss();
}
});
dialog1.show();
dialog1.getWindow().setLayout(1050, 1400);
switch (whichDialog) {
case "predicaoCid.sucesso":
final List<CidVo> list = MyApplicationInstance.getInstanceApplication().getCidVo();
recyclerViewAdapterPredictCid = new CustomRecyclerViewAdapterPredictCid(list, this, new CustomItemClickListener() {
@Override
public void onItemClick(View v, int position) {
list.remove(position);
recyclerViewAdapterPredictProd.notifyDataSetChanged();
}
});
recyclerView.setAdapter(recyclerViewAdapterPredictCid);
break;
case "predicaoProc.sucesso":
final List<PredicaoProcedimentoVo> listProc = MyApplicationInstance.getInstanceApplication().getProcedimentoVosList();
recyclerViewAdapterPredictProd = new CustomRecyclerViewAdapterPredictProd(listProc, this, new CustomItemClickListener() {
@Override
public void onItemClick(View v, int position) {
listProc.remove(position);
recyclerViewAdapterPredictProd.notifyDataSetChanged();
}
});
recyclerView.setAdapter(recyclerViewAdapterPredictProd);
break;
}
}
Adapter:
public class CustomRecyclerViewAdapterPredictProd extends
RecyclerView.Adapter<CustomRecyclerViewAdapterPredictProd.ViewHolder> implements CustomItemClickListener {
private AppCompatActivity appCompatActivity;
private List<PredicaoProcedimentoVo> mDataset;
// Animation
private int lastPosition = -1;
private RadioButton lastCheckedRB = null;
private ItemAgendaVo itemAgendaVo;
private CustomItemClickListener listener;
private View v;
// Provide a suitable constructor (depends on the kind of dataset)
public CustomRecyclerViewAdapterPredictProd(List<PredicaoProcedimentoVo> myDataset, AppCompatActivity appCompatActivity, CustomItemClickListener listener) {
this.appCompatActivity = appCompatActivity;
this.mDataset = myDataset;
this.listener = listener;
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(
ViewGroup parent, int viewType) {
// create a new view
v = LayoutInflater.from(parent.getContext()).inflate(
R.layout.item_predict, parent, false);
// set the view's size, margins, paddings and layout parameters
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
PredicaoProcedimentoVo predicaoCidVo = getProcVo(position);
setAnimation(holder.txtCID, position);
holder.txtCID.setText(predicaoCidVo.getTextPredictedProc());
listener.onItemClick(v,position);//erro ocorre nesta linha TODO
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
if (mDataset != null) {
return mDataset.size();
}
return 0;
}
/**
* @param position
* @return
*/
public PredicaoProcedimentoVo getProcVo(int position) {
return mDataset.get(position);
}
/**
* Here is the key method to apply the animation
*/
private void setAnimation(View viewToAnimate, int position) {
// If the bound view wasn't previously displayed on screen, it's
// animated
if (position > lastPosition) {
Animation animation = AnimationUtils.loadAnimation(
appCompatActivity, android.R.anim.slide_in_left);
// Animation animation = AnimationUtils.loadAnimation(
// appCompatActivity, R.anim.slide_top_to_bottom);
// Animation animation =
// AnimationUtils.loadAnimation(appCompatActivity,
// R.anim.clockwise_rotation);
// animation.setRepeatCount(Animation.START_ON_FIRST_FRAME);
viewToAnimate.startAnimation(animation);
lastPosition = position;
}
}
@Override
public void onItemClick(View v, int position) {
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
static class ViewHolder extends RecyclerView.ViewHolder {
TextView txtCID;
TextView txtCIDDesc;
ViewHolder(View v) {
super(v);
txtCID = itemView.findViewById(R.id.txtCard1_item1);
txtCIDDesc = itemView.findViewById(R.id.txtCard1_item2);
}
}
}
Error occurs in Adapter when it passes through listener.onItemClick(v,position)
I appreciate the help.
Thanks, I ended up answering in English and not here. The error was in Software, I had not implemented it inside a CLICK. Thank you and I mark as an answer!
– Henrique