如果 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
}
我是一名优秀的程序员,十分优秀!