Android Can';没有数据时,在SwiperFresh布局中滑动
我正在我的应用程序中使用带有Android Can';没有数据时,在SwiperFresh布局中滑动,android,android-recyclerview,Android,Android Recyclerview,我正在我的应用程序中使用带有SwipeRefreshLayout的RecyclerView。问题是,当我的RecyclerView有数据时,我可以滑动布局。但当RecyclerView中没有数据时,我就不能刷卡 谁能解决这个问题 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View
SwipeRefreshLayout
的RecyclerView。问题是,当我的RecyclerView有数据时,我可以滑动布局。但当RecyclerView中没有数据时,我就不能刷卡
谁能解决这个问题
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.student_fragment_tutorial_upcoming, container, false);
tvNoData = (TextView) view.findViewById(R.id.tvNoData);
bdn = getArguments();
year = bdn.getString(TutorialStudentFragment.YEARNAME);
Toast.makeText(getContext(), year, Toast.LENGTH_SHORT).show();
networkUtil = new NetworkUtil();
conStatus = networkUtil.getConnectivityStatusString(getContext());
mdbHelper = new DatabaseHelper(getContext());
copyData = new CopyDatabase(getContext());
recyclerTutorial = (RecyclerView) view.findViewById(R.id.recyclerTutorial);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipelayoutTutorial);
swipeRefreshLayout.setColorSchemeResources(R.color.blue, R.color.orange, R.color.green);
if (conStatus.equals("wifi") || conStatus.equals("mobile_data")) {
onRefresh();
} else {
//swipeRefreshLayout.setRefreshing(true);
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
if (mdbHelper.getAllTutorialInfo(year, tutorialType).size() == 0) {
tvNoData.setText("There is no upcoming tutorial for now");
tvNoData.setVisibility(View.VISIBLE);
} else {
tvNoData.setVisibility(View.INVISIBLE);
loadTutorialCard(mdbHelper.getAllTutorialInfo(year, tutorialType));
}
//swipeRefreshLayout.setRefreshing(false);
}
});
}
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getContext(), 1);
recyclerTutorial.setLayoutManager(mLayoutManager);
recyclerTutorial.addItemDecoration(new GridSpacingItemDecoration(1, dpToPx(10), true));
recyclerTutorial.setItemAnimator(new DefaultItemAnimator());
Animation fadeIn = AnimationUtils.loadAnimation(getContext(), R.anim.fade_in);
Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out);
recyclerTutorial.setAnimation(fadeIn);
recyclerTutorial.addOnItemTouchListener(new RecyclerTouchListener(getContext(), recyclerTutorial, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
/* tutorialArrayList = mdbHelper.getAllTutorialInfo(year);
Tutorial tutorial = tutorialArrayList.get(position);
Bundle bdn = new Bundle();*/
Toast.makeText(getContext(), position + " clicked", Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClick(View view, int position) {
}
}));
swipeRefreshLayout.setOnRefreshListener(this);
return view;
}
public void getTutorialData() {
swipeRefreshLayout.setRefreshing(true);
networkUtil = new NetworkUtil();
conStatus = networkUtil.getConnectivityStatusString(getContext());
if (conStatus.equals("wifi") || conStatus.equals("mobile_data")) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, select_tutorial_url,
new Response.Listener<String>() {
ArrayList<Tutorial> tutorialArrayList = new ArrayList<>();
@Override
public void onResponse(String response) {
int count = 0;
if (response.length() > 0) {
while (count < response.length()) {
try {
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(count);
int id = Integer.parseInt(jsonObject.getString("id"));
// String codeStatus =jsonObject.getString("code");
Tutorial tutorial = new Tutorial(id, jsonObject.getString("class_name"), jsonObject.getString("subject"), jsonObject.getString("lesson"), jsonObject.getString("exam_date"), jsonObject.getString("exam_time"), jsonObject.getString("published"));
if (checkTutorialListWithDate(tutorial)) {
tutorialArrayList.add(tutorial);
}
Log.i("Class :", tutorial.getsClass());
Log.i("Subject :", tutorial.getSubject());
Log.i("Lesson :", tutorial.getLesson());
} catch (JSONException e) {
e.printStackTrace();
}
count++;
}
} else {
Toast.makeText(getContext(), String.valueOf(response.length()), Toast.LENGTH_SHORT).show();
}
swipeRefreshLayout.setRefreshing(false);
loadTutorialCard(tutorialArrayList);
if (tutorialArrayList.size() == 0) {
tvNoData.setVisibility(View.VISIBLE);
tvNoData.setText("There is no upcoming tutorial for now");
} else {
tvNoData.setVisibility(View.INVISIBLE);
}
workingWithLocalDatabase(tutorialArrayList, mdbHelper.getAllTutorialInfo(year, tutorialType));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
swipeRefreshLayout.setRefreshing(false);
NetworkUtil.checkInternetConnection(error, getContext(), swipeRefreshLayout);
}
}
) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("studentYear", year);
return params;
}
};
Mysingleton.getInstance(getContext()).addToRequestque(stringRequest);
} else {
swipeRefreshLayout.setRefreshing(false);
networkUtil.showNetError(getContext(), swipeRefreshLayout);
}
}
public void onRefresh() {
getTutorialData();
}
public View onCreateView(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图=充气机。充气(R.layout.student\u fragment\u tutorial\u container,false);
tvNoData=(TextView)view.findViewById(R.id.tvNoData);
bdn=getArguments();
year=bdn.getString(TutorialStudentFragment.name);
Toast.makeText(getContext(),year,Toast.LENGTH_SHORT).show();
networkUtil=新的networkUtil();
conStatus=networkUtil.getConnectivityStatusString(getContext());
mdbHelper=新数据库助手(getContext());
copyData=新的CopyDatabase(getContext());
recyclerTutorial=(RecyclerView)view.findViewById(R.id.recyclerTutorial);
swipeRefreshLayout=(swipeRefreshLayout)view.findViewById(R.id.swipelayoutTutorial);
swipeRefreshLayout.setColorSchemeResources(R.color.blue、R.color.orange、R.color.green);
if(conStatus.equals(“wifi”)| | conStatus.equals(“移动_数据”)){
onRefresh();
}否则{
//swipeRefreshLayout.setRefreshing(true);
swipeRefreshLayout.post(新的Runnable(){
@凌驾
公开募捐{
if(mdbHelper.getAllTutorialInfo(年份,tutorialType).size()=0){
setText(“目前还没有即将推出的教程”);
设置可见性(View.VISIBLE);
}否则{
设置可见性(视图不可见);
loadTutorialCard(mdbHelper.getAllTutorialInfo(年份,tutorialType));
}
//swipeRefreshLayout.setRefreshing(false);
}
});
}
RecycleView.LayoutManager mLayoutManager=新的GridLayoutManager(getContext(),1);
RecyclerAutorial.setLayoutManager(mLayoutManager);
RecyclerAutorial.addItemDecoration(新的GridSpacingItemDecoration(1,dpToPx(10),真));
setItemAnimator(新的DefaultItemAnimator());
Animation fadeIn=AnimationUtils.loadAnimation(getContext(),R.anim.fade_-in);
Animation fadeOut=AnimationUtils.loadAnimation(getContext(),R.anim.fade_);
设置动画(fadeIn);
AddOnItemToucListener(新的RecyclerToucListener(getContext(),RecyclerToUrial,新的RecyclerToucListener.ClickListener()){
@凌驾
公共void onClick(视图,int位置){
/*tutorialArrayList=mdbHelper.getAllTutorialInfo(年);
Tutorial Tutorial=tutorialArrayList.get(位置);
Bundle bdn=新Bundle()*/
Toast.makeText(getContext(),position+“clicked”,Toast.LENGTH_SHORT.show();
}
@凌驾
仅长按公共无效(视图,int位置){
}
}));
swipeRefreshLayout.setOnRefreshListener(此);
返回视图;
}
public void getTutorialData(){
swipeRefreshLayout.setRefreshing(true);
networkUtil=新的networkUtil();
conStatus=networkUtil.getConnectivityStatusString(getContext());
if(conStatus.equals(“wifi”)| | conStatus.equals(“移动_数据”)){
StringRequest StringRequest=新建StringRequest(Request.Method.POST,选择教程\u url,
新的Response.Listener(){
ArrayList教程ArrayList=新建ArrayList();
@凌驾
公共void onResponse(字符串响应){
整数计数=0;
if(response.length()>0){
while(count