I have RecyclerView, but data doesn't show in it.
I tried using the notifydatasetchange()
but that didn't help and RecyclerView didn't update.
Here is my code :
Adapter class
public class Price_Adapter extends RecyclerView.Adapter<Price_Adapter.viewHolder> {
private Context mctx;
private List<Price_Model>modelList;
public Price_Adapter(Context mctx, List<Price_Model> modelList) {
this.mctx = mctx;
this.modelList = modelList;
}
@NonNull
@Override
public viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mctx);
View view = inflater.inflate(R.layout.pricelist_row,parent,false);
return new viewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull viewHolder holder, int position) {
Price_Model price_model = modelList.get(position);
holder.item.setText(price_model.getItem());
holder.price.setText(price_model.getPrice());
}
@Override
public int getItemCount() {
return modelList.size();
}
public class viewHolder extends RecyclerView.ViewHolder {
private TextView item,price;
private CheckBox checkBox;
public viewHolder(@NonNull View itemView) {
super(itemView);
item = itemView.findViewById(R.id.item);
price = itemView.findViewById(R.id.price);
checkBox = itemView.findViewById(R.id.checkBox);
}
}
}
Model Class:
public class Price_Model {
private String item, price;
public Price_Model() {
}
public Price_Model(String item, String price) {
this.item = item;
this.price = price;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
Main code:
pricelist_recyclerView = view.findViewById(R.id.recyclerView_pricelist);
pricelist_recyclerView.setHasFixedSize(true);
pricelist_recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(),RecyclerView.VERTICAL,false));
pricelist_recyclerView.setAdapter(price_adapter);
priceModelList = new ArrayList<>();
price_adapter = new Price_Adapter(getActivity(),priceModelList);
priceModelList.add(new Price_Model("rytdfy","fhf"));
priceModelList.add(new Price_Model("rytdfy","fhf"));
priceModelList.add(new Price_Model("rytdfy","fhf"));
priceModelList.add(new Price_Model("rytdfy","fhf"));
I am getting this error in my Logcat:
2020-05-23 14:53:33.238 1736-1736/? E/chooseup.barbe: Unknown bits set in runtime_flags: 0x28000
2020-05-23 14:53:34.996 1736-1736/com.chooseup.barber E/ANR_LOG: >>> msg's executing time is too long
2020-05-23 14:53:34.996 1736-1736/com.chooseup.barber E/ANR_LOG: Blocked msg = { when=-1s637ms what=110 target=android.app.ActivityThread$H obj=AppBindData{appInfo=ApplicationInfo{d5a0e0e com.chooseup.barber}} } , cost = 1636 ms
2020-05-23 14:53:34.996 1736-1736/com.chooseup.barber E/ANR_LOG: >>>Current msg List is:
2020-05-23 14:53:35.005 1736-1736/com.chooseup.barber E/ANR_LOG: Current msg <1> = { when=-1s636ms what=0 target=android.app.ActivityThread$H callback=com.android.internal.util.function.pooled.PooledLambdaImpl }
2020-05-23 14:53:35.005 1736-1736/com.chooseup.barber E/ANR_LOG: Current msg <2> = { when=-587ms what=0 target=android.app.ActivityThread$H callback=com.android.internal.util.function.pooled.PooledLambdaImpl }
2020-05-23 14:53:35.005 1736-1736/com.chooseup.barber E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
2020-05-23 14:53:35.007 1736-2486/com.chooseup.barber E/Perf: Fail to get file list com.chooseup.barber
2020-05-23 14:53:35.008 1736-2486/com.chooseup.barber E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-05-23 14:53:35.009 1736-2486/com.chooseup.barber E/Perf: Fail to get file list com.chooseup.barber
2020-05-23 14:53:35.009 1736-2486/com.chooseup.barber E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array