E/RecyclerView: No adapter attached; skipping layout not showing the data in recyclerview

后端 未结 1 2078
一个人的身影
一个人的身影 2021-01-26 17:04

Can any one help with the solution here i am getting the ERROR that

E/RecyclerView: No adapter attached; skipping layout

here are my files.

OneFragment.

相关标签:
1条回答
  • 2021-01-26 17:50

    You need to return drawer; instead of inflater.inflate(R.layout.fragment_one, container, false); inside onCreateView()

    EDIT

    @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {
    
                View drawer = inflater.inflate(R.layout.fragment_one, container, false);
    
                feedsList = new ArrayList<FeedItem>();
                mRecyclerView = (RecyclerView) drawer.findViewById(R.id.recycler_view);
    
                mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
                progressBar = (ProgressBar) drawer.findViewById(R.id.progress_bar);
                String url = "http://krishscs.esy.es/RecycleViewExample/RecycleViewExample.php";
                mSearchView = (SearchView) drawer.findViewById(R.id.search_view);
                setupSearchView();
                new DownloadTask().execute(url);
                adapter = new MyRecyclerViewAdapter(getActivity(),feedsList);
                Toast.makeText(getActivity(), "HELLO", Toast.LENGTH_SHORT).show();
                mRecyclerView.setAdapter(adapter);
    
    
                // Inflate the layout for this fragment
                return drawer;
            }
    

    Try this

    private void parseResult(String result) {
                try {
                    feedsList = new ArrayList<FeedItem>();
                    JSONObject response = new JSONObject(result);
                    JSONArray posts = response.optJSONArray("result");
                    for (int i = 0; i < posts.length(); i++) {
                        JSONObject post = posts.optJSONObject(i);
                        FeedItem item = new FeedItem();
                        item.setTitle(post.optString("name"));
                        item.setThumbnail(post.optString("image"));
                        feedsList.add(item);
                    }
                    adapter = new MyRecyclerViewAdapter(getActivity(),feedsList);
    
                    mRecyclerView.setAdapter(adapter);
                    Log.d("POSTDATA",feedsList.toString() );
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
    
    0 讨论(0)
提交回复
热议问题