使用recyclerView无法显示数据

时间:2016-08-24 05:07:53

标签: android android-recyclerview

Android屏幕上没有显示数据,我也没有在LogCat中收到任何错误。在LogCat中,它显示数据但不在屏幕上显示。我搜索了很多东西,但没有得到任何答案。我使用__VA_ARGS__来显示数据。

这是我的代码 - RecyclerView

MainActivity

以下是我的适配器代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_activity);
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    gAdapter = new GetJobDetailsAdapter(detailsJob);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView .setLayoutManager(mLayoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
     String url = "url"

    AQuery mAQuery = new AQuery(SecondActivity.this);
    mAQuery.ajax(url, String.class, new AjaxCallback<String>() {
        @Override
        public void callback(String url, String data, AjaxStatus status) {
            super.callback(url, data, status);
            if (null != data && status.getCode() != -101) {

                String StringData = "" + data;
                try {
                    JSONArray rootArray = new JSONArray(StringData);
                    int len = rootArray.length();
                    for (int i = 0; i < len; ++i) {
                        JSONObject json = rootArray.optJSONObject(i);

                        GetJobDetailsJobs b1 = new GetJobDetailsJobs();
                        b1.About_Company = json.optString("Req_Additional_Details");
                        b1.Designation = json.optString("Req_Designation_Role");
                        b1.Eligibility = json.optString("JobTitle");
                        b1.JobLocation = json.optString("Job_Location");
                        b1.JobDescription=json.optString("Req_Project_Desc");


                        detailsJob.add(b1);


                    }
                } catch (JSONException e) {
                    Toast.makeText(SecondActivity.this, e.toString(), Toast.LENGTH_LONG).show();

                }
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

您没有在代码中将适配器设置为recyclerview。 &#34; recyclerView.setAdapter(gAdapter)&#34;在onCreate或Ajax回调中设置它。

   recyclerView.setAdapter(gAdapter)

从Ajax回调中获取jobDetails后,您必须将其设置为适配器。

gAdapter.setJobDetailsAdapterData(your_jobs_data);

然后它将设置数据并调用notifyDataSetChanged。

<强>适配器: 这应该是一个setJobDetailsAdapter。

public void setJobDetailsAdapterData(List<GetJobDetailsJobs>detailsJob){
        this.detailsJob=detailsJob;
        notifyDataSetChanged();
    }