My Recyclerview is not showing anything

前端 未结 5 1893
自闭症患者
自闭症患者 2021-01-23 13:35

I want to display Items from the mysql database to my recyclerview but I dont know why it is not displaying anything

Recyclerview



        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 14:12

    Try this code .. make one method for set adapter..

        private void setAdapter(){
        if (likelyProblemAdapter==null){
            if (!mlikelyProblems.isEmpty()) {
                likelyProblemAdapter = new LikelyProblemAdapter(mlikelyProblems, this);
                mRecyclerView.setAdapter(likelyProblemAdapter);
            }
        }
        else{
            likelyProblemAdapter.notifyDataSetChanged();
    
        }
    }
    

    this method define after getting all data like this way..

     try {
                JSONArray jsonArray = new JSONArray(response);
                for (int i=0; i<=jsonArray.length()-1; i++){
                    JSONObject likelyProblemJson = jsonArray.getJSONObject(i);
                    likelyProblem = likelyProblemJson.getString("problems");
                    LikelyProblems likelyProblems = new LikelyProblems(likelyProblem);
                    mlikelyProblems.add(likelyProblems);
                    mRecyclerView.setAdapter(likelyProblemAdapter);
                }
              setAdapter();
    
            } catch (JSONException e) {
                e.printStackTrace();
            }
    

提交回复
热议问题