RecyclerView
没有显示任何内容
这是我的oncreate view
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_money_transfer_customers, null);
validate = (Button)v.findViewById(R.id.validate);
delete = (Button)v.findViewById(R.id.delete);
reinitiate = (Button)v.findViewById(R.id.reinitiate);
transfer = (Button)v.findViewById(R.id.transfer);
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
recyclerView = (RecyclerView) v.findViewById(R.id.transactio_rep_recyclerView);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
userValidate = (UserValidate)getArguments().getSerializable("UserValidate");
new ValidateUser().execute();
return v;
}
这就是我如何将适配器设置为回收器视图......
adapter = new MoneyTransferCustomersCardAdapter(beneficiaryDetailsList,this);
recyclerView.setAdapter(adapter);
这是我的适配器类......
public class MoneyTransferCustomersCardAdapter extends RecyclerView.Adapter<MoneyTransferCustomersCardAdapter.ViewHolder>{
MoneyTransferCustomersCardAdapter moneyTransferCustomersCardAdapter = this;
List<BeneficiaryDetails> beneficiaryDetailsList;
public MoneyTransferCustomersCardAdapter(List<BeneficiaryDetails> beneficiaryDetailsList, MoneyTransferCustomersFragment.ValidateUser MoneyTransferCardAdapter) {
super();
this.beneficiaryDetailsList = beneficiaryDetailsList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.money_transfer_customers_card, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
final Animation anim_record_item = AnimationUtils.loadAnimation(parent.getContext(), R.anim.swipe_down);
viewHolder.itemView.startAnimation(anim_record_item);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
try{
BeneficiaryDetails bd = beneficiaryDetailsList.get(position);
holder.vtxtName.setText(bd.getBeneficiaryName());
holder.vtxtAccount.setText(bd.getAccountNumber());
holder.vtxtIfsc.setText(bd.getIFSC());
}catch(Exception e){
}
}
@Override
public int getItemCount() {
return 0;
}
class ViewHolder extends RecyclerView.ViewHolder {
public TextView vtxtName;
public TextView vtxtAccount;
public TextView vtxtIfsc;
public CardView cardViewTxCardItem;
public ViewHolder(View itemView) {
super(itemView);
final View view = itemView;
vtxtName = (TextView) itemView.findViewById(R.id.name);
vtxtAccount = (TextView) itemView.findViewById(R.id.account);
vtxtIfsc = (TextView) itemView.findViewById(R.id.ifsc);
cardViewTxCardItem = (CardView) itemView.findViewById(R.id.cardview_tx_card_item);
}
}
}
以上代码工作正常....但回收者视图没有显示任何内容.....
Log RecyclerView: No adapter attached; skipping layout
答案 0 :(得分:1)
您需要return
适配器中的数据大小而不是0
,否则Adpater
将始终认为没有要显示的数据。
@Override
public int getItemCount() {
return beneficiaryDetailsList.size();
//^^^^^^^ return list size , actual length of data to be displayed
}