2017-03-16 2 views
-1
public void getResponseForAllMilkHistory(Response response) 
    { 
//  Log.e("Response", "inside getResponseForAllMilkHistory "); 

     Log.e("Response", "In response"); 
     JSONObject jsonobject = null; 
     try{ 
      //ArrayList<MilkDbModel> data=new ArrayList<>(); 
      if (response.getIs_success()){ 
       jsonobject = new JSONObject(response.getData()); 
       Log.e("check", jsonobject.toString()); 
       MilkDbModel dbData=new MilkDbModel(); 
       dbData.milk_id=jsonobject.getInt("milk_id"); 
       dbData.shop_name=jsonobject.getString("shop_name"); 
       dbData.date=jsonobject.getString("date"); 
       dbData.shift=jsonobject.getString("shift"); 
       dbData.cow_milk=jsonobject.getDouble("cow_milk"); 
       dbData.buffalo_milk=jsonobject.getDouble("buffalo_milk"); 
       dbData.cow_milk_price=jsonobject.getDouble("cow_milk_price"); 
       dbData.buffalo_milk_price=jsonobject.getDouble("buffalo_milk_price"); 

      }else{ 
       jsonobject = new JSONObject(response.getData()); 
        Log.e("error", jsonobject.toString()); 
      } 
+1

Wo ist dein recycleview Code? ? – tahsinRupam

+0

Dies ist onCreate() – kirans

+0

@ tahsinRupam, können Sie Ihren Recycling-Code schreiben? – shahid17june

Antwort

0

in Ihrem onCreate

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 
recyclerView.setHasFixedSize(true); 
recyclerView .setLayoutManager(new LinearLayoutManager(this)); 
YourAdapter_Class adapter= new YourAdapter_Class(arraylist/linklist or whatever parameter is); 
recyclerView.setAdapter(adapter); 

und wenn Sie Daten analysieren, dann benachrichtigen Adapter wie diese

recyclerView.notifyDataSetChanged(); 
+0

@kirans, lassen Sie mich wissen, wenn es irgendein Problem gibt – shahid17june

+0

danke für die Zeit geben – kirans

+0

@ kirans, bitte akzeptieren Sie die Antwort, wenn funktioniert, damit andere Person es verwenden kann. – shahid17june

-1
try { 
    ArrayList<MilkDbModel> data = new ArrayList<>(); 
    if (response.getIs_success()) { 
     jsonobject = new JSONObject(response.getData()); 
     Log.e("check", jsonobject.toString()); 

     for (int i = 0; i < jsonobject.length(); i++) { 
      MilkDbModel dbData = new MilkDbModel(); 
      dbData.milk_id = jsonobject.getJSONObject(i).getInt("milk_id"); 
      dbData.shop_name = jsonobject.getJSONObject(i).getString("shop_name"); 
      dbData.date = jsonobject.getJSONObject(i).getString("date"); 
      dbData.shift = jsonobject.getJSONObject(i).getString("shift"); 
      dbData.cow_milk = jsonobject.getJSONObject(i).getDouble("cow_milk"); 
      dbData.buffalo_milk = jsonobject.getJSONObject(i).getDouble("buffalo_milk"); 
      dbData.cow_milk_price = jsonobject.getJSONObject(i).getDouble("cow_milk_price"); 
      dbData.buffalo_milk_price = jsonobject.getJSONObject(i).getDouble("buffalo_milk_price"); 
      data.add(dbData) 
     } 
     setadapter(data) 
    } else { 
     jsonobject = new JSONObject(response.getData()); 
     Log.e("error", jsonobject.toString()); 
    } 
} catch(Exception e){ 
    e.printStackTrace(); 
} 


public void setadapter(ArrayList<MilkDbModel> list) { 
    adapter = new NameOfTheAdapter(getActivity(), list); 
    LinearLayoutManager layoutManager 
      = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); 
    recyclerView.setLayoutManager(layoutManager); 
    recyclerView.setAdapter(adapter); 
} 
Verwandte Themen