Recyclerview没有连接适配器

时间:2017-08-26 11:08:16

标签: android

一切正常。但是在logcat中显示了一些错误。

  

E / RecyclerView:没有连接适配器;跳过布局
   E / RecyclerView:没有连接适配器;跳过布局

我的活动代码:

Recyclerview recyclerView = findViewById( R.id.Recyclerview );
LinearLayoutManager  layoutManager = new LinearLayoutManager( this, LinearLayoutManager.VERTICAL, false );
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(toolbaradapter);

我已经阅读了与同一问题相关的其他问题但没有任何帮助。 请帮帮我

1 个答案:

答案 0 :(得分:0)

My Activity class:

   public class HelpToolBar extends Activity {
   RecyclerView.Adapter toolbaradapter;
    RecyclerView.LayoutManager layoutManager;
    Header header;
   Recyclerview recyclerView;
    public List<String> List;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toolbar);
        List = new ArrayList<>();
    Recyclerview recyclerView = findViewById( R.id.Recyclerview );
        toolbaradapter= new ToolAdapter(HelpToolBar.this,List);
    LinearLayoutManager  layoutManager = new LinearLayoutManager( this, LinearLayoutManager.VERTICAL, false );
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(toolbaradapter);

      userLogin();

    }

    private void userLogin() {
         final JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url,
                null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                String code = response.optString("success");
                if (code.equals("true")) {
                    try {
                            JSONObject obj = response.getJSONObject("data");
                        JSONArray abc = obj.getJSONArray("list");
                            for(int i = 0; i < abc.length();i++) {
                                JSONObject item = abc.getJSONObject(i);
                                List.add(item.getString("date"));

                            }
                           toolbaradapter= new ToolAdapter(HelpToolBar.this,List);
                            recyclerView.setAdapter(toolbaradapter);

                        } catch (JSONException e) {
                            progressbar.hidePDialog();
                            e.printStackTrace();
                        }
                }
                progressbar.hidePDialog();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("", "Error: " + error.getMessage());
                Log.e("", "Site Info Error: " + error.getMessage());
                progressbar.hidePDialog();
            }
        })
        {@Override
            public Map<String, String> getHeaders() throws AuthFailureError {
            return header.getHeaders();
            }
        };
        RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        requestQueue.add(req);
    }
}

My Adapter class:

public class ToolAdapter extends RecyclerView.Adapter<ToolAdapter.ViewHolder> {
    Context context;
   private List<String> List

    public ToolAdapter(HelpToolBar helpToolBar, List<String> List) {
        this.context= helpToolBar;
        this.List=List;

    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemLayoutView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.helptooladapter,parent, false);
        return new ViewHolder(itemLayoutView);
    }
    @Override
    public void onBindViewHolder(final ViewHolder holder,  int position) {
        holder.textview1.setText(List.get(position) );


    }
    @Override
    public int getItemCount() {
        return List.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
       public   TextView1 
       public ViewHolder(View itemView) {
            super(itemView);
            textview1= itemView.findViewById(R.id.tooladtextview);

        }
    }
}