gpt4 book ai didi

java - 如果 Json 中的列表为空,我只想留言...那么我该怎么做...在 recyclerview 中遇到很多冲突

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:04 24 4
gpt4 key购买 nike

如果 Json 中的列表为空,我只想留言...那么我该怎么做...在 recyclerview 中遇到很多冲突

一个简单的 {@link Fragment} 子类。

public class TodayFragment extends Fragment implements ViewPager.OnPageChangeListener {

public static final String URL_DATA =Url.GET_TODAY_UPDATE;
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
String currentDate="2017-06-29";
private List<TodayList> listViews;
private TextView totalPaidFees;



public TodayFragment() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
loadRecyclerViewData();
return view;
}

private void loadRecyclerViewData() {

final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Loading...");
progressDialog.show();

SingletoneRequst.q(getContext()).add(new StringRequest(Request.Method.GET, URL_DATA+currentDate , new Response.Listener<String>() {


@Override
public void onResponse(String response) {
progressDialog.dismiss();
Log.i("@url_T","url--"+URL_DATA);
Log.i("@today", "Json--"+response.toString());
Gson gson = new Gson();
TodayFees list = (gson.fromJson(response, TodayFees.class));

List<TodayList> lists = list.getTodayList();
for (TodayList todayList : lists) {
Log.i("today", "" + todayList);

}
totalPaidFees.setText(list.getTotalFees().toString());
adapter = new Adapter_TodayFees(lists, getContext());
recyclerView.setAdapter(adapter);


}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getActivity(), "Network problem!! Check your internet connection", Toast.LENGTH_LONG).show();
}
}));

}




@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {

}

@Override
public void onPageScrollStateChanged(int state) {

}
}

最佳答案

就这样吧...

List<TodayList> lists = list.getTodayList();
if(lists!=null && lists.size>0){
for (TodayList todayList : lists) {
Log.i("today", "" + todayList);

}
totalPaidFees.setText(list.getTotalFees().toString());
adapter = new Adapter_TodayFees(lists, getContext());
recyclerView.setAdapter(adapter);
}
else{
//Show the message here
}

关于java - 如果 Json 中的列表为空,我只想留言...那么我该怎么做...在 recyclerview 中遇到很多冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44899667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com