Recycler Adapter 未设置的一些数据
Some data not set by Recycler Adapter
这是我的 createView。我在日志 cat 中看到所有数据都可用,但某些数据未在适配器中设置。余额卡不是回收站视图的一部分。这是在片段中完成的。当调用此片段的 oncreate 视图时,出现错误 No adapter attached;跳过布局错误。我认为它希望我在初始化回收器视图后立即附加一个适配器,但由于我在获取所有数据后附加一个适配器,所以它可能会抛出错误,但我仍然没有对未看到的数据的解释在某些方面。
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.payment,null);
currentBalance = (TextView) rootView.findViewById(R.id.current_balance);
paymentsRecyclerView = (RecyclerView) rootView.findViewById(R.id.payments_recycler_view);
Constants.paymentsData = new ArrayList<PaymentsData>();
paymentsRecyclerView.setHasFixedSize(true);
paymentsLayoutManager = new LinearLayoutManager(getActivity());
paymentsRecyclerView.setLayoutManager(paymentsLayoutManager);
new FetchPaymentAsyncTask(getActivity().getApplicationContext(),new FetchPaymentAsyncTask.FetchPaymentCallback() {
@Override
public void onStart(boolean a) {
dialog = new ProgressDialog(getActivity());
dialog.setTitle("Getting Your Payment Details");
dialog.setMessage("Loading... please wait");
dialog.show();
dialog.setCancelable(false);
}
@Override
public void onResult(boolean b) {
if(b){
dialog.dismiss();
currentBalance.setText(getActivity().getApplicationContext().getString(R.string.Rs)+" "+Constants.currentBalance);
paymentsAdapter = new PaymentsAdapter(Constants.paymentsData, getActivity().getApplicationContext());
paymentsRecyclerView.setAdapter(paymentsAdapter);
}
else{
dialog.dismiss();
AlertDialog builder = new AlertDialog.Builder(getActivity()).create();
builder.setTitle("Payment Details");
builder.setMessage("No Payment Records");
builder.show();
}
}
}).execute(Constants.fetchPaymentURL+Constants.merchantId);
return rootView;
}
问题已解决。我是在 Adapter class 上玩 VISIBILITY 的。感谢帮助
这是我的 createView。我在日志 cat 中看到所有数据都可用,但某些数据未在适配器中设置。余额卡不是回收站视图的一部分。这是在片段中完成的。当调用此片段的 oncreate 视图时,出现错误 No adapter attached;跳过布局错误。我认为它希望我在初始化回收器视图后立即附加一个适配器,但由于我在获取所有数据后附加一个适配器,所以它可能会抛出错误,但我仍然没有对未看到的数据的解释在某些方面。
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.payment,null);
currentBalance = (TextView) rootView.findViewById(R.id.current_balance);
paymentsRecyclerView = (RecyclerView) rootView.findViewById(R.id.payments_recycler_view);
Constants.paymentsData = new ArrayList<PaymentsData>();
paymentsRecyclerView.setHasFixedSize(true);
paymentsLayoutManager = new LinearLayoutManager(getActivity());
paymentsRecyclerView.setLayoutManager(paymentsLayoutManager);
new FetchPaymentAsyncTask(getActivity().getApplicationContext(),new FetchPaymentAsyncTask.FetchPaymentCallback() {
@Override
public void onStart(boolean a) {
dialog = new ProgressDialog(getActivity());
dialog.setTitle("Getting Your Payment Details");
dialog.setMessage("Loading... please wait");
dialog.show();
dialog.setCancelable(false);
}
@Override
public void onResult(boolean b) {
if(b){
dialog.dismiss();
currentBalance.setText(getActivity().getApplicationContext().getString(R.string.Rs)+" "+Constants.currentBalance);
paymentsAdapter = new PaymentsAdapter(Constants.paymentsData, getActivity().getApplicationContext());
paymentsRecyclerView.setAdapter(paymentsAdapter);
}
else{
dialog.dismiss();
AlertDialog builder = new AlertDialog.Builder(getActivity()).create();
builder.setTitle("Payment Details");
builder.setMessage("No Payment Records");
builder.show();
}
}
}).execute(Constants.fetchPaymentURL+Constants.merchantId);
return rootView;
}
问题已解决。我是在 Adapter class 上玩 VISIBILITY 的。感谢帮助