0

확장 가능한 RecyclerView를 만들고 있습니다. 문제는 ArrayList에있는 데이터가 있지만 어댑터가 설정되지 않습니다.확장 가능한 RecyclerView 어댑터가 설정되지 않습니다

나는 어댑터를 arrayListNotiTypes.add ("About SMS", addNotiToParticularNotiType (jaSms, ""))) 뒤에 설정하여 시도했습니다.이 줄이 있지만 같은 오류가 발생합니다. 이 모듈은 다른 유형의 확장 가능한 RecyclerView를 만들었습니다. 거기에서 잘 작동합니다. 다음은

Notification_Activity.java

public class Notification_Activity extends AppCompatActivity { 

    // Widgets 
    private ProgressDialog progressDialog; 
    private RecyclerView recyclerView_Noti; 

    // Variables 
    private String url = "notification.php"; 
    private ArrayList<NotiTypes> arrayListNotiTypes; 
    private ArrayList<ActualNotis> arrayListActualNotis; 

    // Others 
    private AdapterNotification adapterNoti; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_notification); 

     find_view_by_id(); 
     init(); 

     if (Commom_Methods.isNetworkAvailable(this)) { 
      fetchData(); 
     } else { 
      Toast.makeText(this, "Please, Coonect to internet!!", Toast.LENGTH_SHORT).show(); 
     } 

     // Setting Adapter for Notification 
     adapterNoti = new AdapterNotification(Notification_Activity.this, arrayListNotiTypes); 
     recyclerView_Noti.setAdapter(adapterNoti); 
     recyclerView_Noti.setLayoutManager(new LinearLayoutManager(Notification_Activity.this)); 
    } 

    private void find_view_by_id() { 
     recyclerView_Noti = (RecyclerView) findViewById(R.id.recycle_noti); 
    } 

    private void init() { 
     arrayListNotiTypes = new ArrayList<>(); 
    } 

    private void fetchData() { 
     StringRequest stringReq = new StringRequest(Request.Method.POST, Constants.base_url + url, new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
       Log.e("onResponse: ", response); 
       progressDialog.dismiss(); 
       if (response != null) { 
        try { 
         JSONObject jo = new JSONObject(response); 
         if (jo.has("success")) { 

          JSONObject joNoti = jo.getJSONObject("notification"); 

          /*JSONArray jaStu = joNoti.getJSONArray("noti_student"); 
          arrayListNotiTypes.add(new NotiTypes("About Student", addNotiToParticularNotiType(jaStu, "")));*/ 

          JSONArray jaBatch = joNoti.getJSONArray("noti_batch"); 
          arrayListNotiTypes.add(new NotiTypes("About Batch", addNotiToParticularNotiType(jaBatch, ""))); 

          JSONArray jaInst = joNoti.getJSONArray("noti_institute"); 
          arrayListNotiTypes.add(new NotiTypes("About Institute", addNotiToParticularNotiType(jaInst, "attach"))); 

          JSONArray jaFee = joNoti.getJSONArray("noti_fee"); 
          arrayListNotiTypes.add(new NotiTypes("About Fees", addNotiToParticularNotiType(jaFee, "attach"))); 

          JSONArray jaSms = joNoti.getJSONArray("noti_sms"); 
          arrayListNotiTypes.add(new NotiTypes("About SMS", addNotiToParticularNotiType(jaSms, ""))); 

         } else { 
          Toast.makeText(getApplicationContext(), jo.getString("error_msg"), Toast.LENGTH_LONG).show(); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } else { 
        Toast.makeText(getApplicationContext(), "Server error! Don't get Data from server. Try again later.", Toast.LENGTH_LONG).show(); 
       } 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       progressDialog.dismiss(); 
       Toast.makeText(getApplicationContext(), "Error:" + error.getMessage(), Toast.LENGTH_LONG).show(); 
      } 
     }) { 
      @Override 
      protected Map<String, String> getParams() { 
       Map<String, String> params = new HashMap<String, String>(); 
       params.put("id", Preferences.readString(getApplicationContext(), Preferences.KEY_SL_ID, "")); 
       params.put("tution_center_sl", Preferences.readString(getApplicationContext(), Preferences.KEY_TUTION_CENTER_SL, "")); 
       params.put("batch_sl", Preferences.readString(getApplicationContext(), Preferences.KEY_BATCH_SL, "")); 
       params.put("batch_grup_sl", Preferences.readString(getApplicationContext(), Preferences.KEY_BATCH_GRUP_SL, "")); 
       params.put("co_sl", Preferences.readString(getApplicationContext(), Preferences.KEY_CO_SL, "")); 
       params.put("drange_sl", Preferences.readString(getApplicationContext(), Preferences.KEY_DRANGE_SL, "")); 
       return params; 
      } 

      @Override 
      public Map<String, String> getHeaders() throws AuthFailureError { 
       HashMap<String, String> headers = new HashMap<String, String>(); 
       headers.put("X-Apikey", Preferences.readString(getApplicationContext(), Preferences.KEY_USER_XAPIKEY, "")); 
       return headers; 
      } 
     }; 
     RequestQueue queue = Volley.newRequestQueue(this); 
     queue.add(stringReq); 

     progressDialog = new ProgressDialog(this); 
     progressDialog.setMessage("Loading..."); 
     progressDialog.show(); 
    } 

    private ArrayList<ActualNotis> addNotiToParticularNotiType(JSONArray jsonArray, String attachments) throws JSONException { 
     arrayListActualNotis = new ArrayList<>(); 
     if (jsonArray.length() > 0) { 
      for (int j = 0; j < jsonArray.length(); j++) { 
       JSONObject joInner = jsonArray.getJSONObject(j); 
       String notiTitle = joInner.getString("title"); 
       String notiDesc = joInner.getString("decription"); 
       String attach = ""; 
       if (!attachments.equals("")) 
        attach = joInner.getString("attach"); 
       arrayListActualNotis.add(new ActualNotis(notiTitle, notiDesc, attach)); 
      } 
     } else { 
      arrayListActualNotis.add(new ActualNotis("No Notifications!!", "", "")); 
     } 
     return arrayListActualNotis; 
    } 
} 

.. 내가 시도 무엇

public class AdapterNotification extends ExpandableRecyclerViewAdapter<AdapterNotification.NotiTypesViewHolder, AdapterNotification.ActualNotisViewHolder> { 

    private Activity mActivity; 

    public AdapterNotification(Activity activity, List<? extends ExpandableGroup> groups) { 
     super(groups); 
     this.mActivity = activity; 
    } 

    @Override 
    public NotiTypesViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) { 
     LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     View view = inflater.inflate(R.layout.noti_type_group_view_holder, parent, false); 
     return new NotiTypesViewHolder(view); 
    } 

    @Override 
    public ActualNotisViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) { 
     LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     View view = inflater.inflate(R.layout.actual_notis_child_view_holder, parent, false); 
     return new ActualNotisViewHolder(view); 
    } 

    @Override 
    public void onBindGroupViewHolder(NotiTypesViewHolder holder, int flatPosition, ExpandableGroup group) { 
     holder.setGroupName(group); 
    } 

    @Override 
    public void onBindChildViewHolder(ActualNotisViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) { 
     final ActualNotis notis = ((NotiTypes) group).getItems().get(childIndex); 
     holder.onBind(notis, group); 
    } 

    public class NotiTypesViewHolder extends GroupViewHolder { 

     private TextView txt_noti_type; 

     public NotiTypesViewHolder(View itemView) { 
      super(itemView); 
      txt_noti_type = (TextView) itemView.findViewById(R.id.txt_noti_type); 
     } 

     @Override 
     public void expand() { 
      txt_noti_type.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.up_arrow, 0); 
      Log.e("Adapter", "Expand"); 
     } 

     @Override 
     public void collapse() { 
      txt_noti_type.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.down_arrow, 0); 
      Log.e("Adapter", "collapse"); 
     } 

     public void setGroupName(ExpandableGroup group) { 
      txt_noti_type.setText(group.getTitle()); 
     } 
    } 

    public class ActualNotisViewHolder extends ChildViewHolder { 

     private TextView txt_noti, txt_noti_desc; 

     public ActualNotisViewHolder(View itemView) { 
      super(itemView); 
      txt_noti = (TextView) itemView.findViewById(R.id.txt_noti); 
      txt_noti_desc = (TextView) itemView.findViewById(R.id.txt_noti_desc); 
     } 

     public void onBind(ActualNotis actualNotis, ExpandableGroup group) { 
      switch (actualNotis.getmNotiTitle()) { 
       case "noti_student": 
        txt_noti.setText(actualNotis.getmNotiTitle()); 
        txt_noti_desc.setText(actualNotis.getmNotiDesc()); 
        break; 
       case "noti_batch": 
        txt_noti.setText(actualNotis.getmNotiTitle()); 
        txt_noti_desc.setText(actualNotis.getmNotiDesc()); 
        break; 
       case "noti_institute": 
        txt_noti.setText(actualNotis.getmNotiTitle()); 
        txt_noti_desc.setText(actualNotis.getmNotiDesc()); 
        break; 
       case "noti_fee": 
        txt_noti.setText(actualNotis.getmNotiTitle()); 
        txt_noti_desc.setText(actualNotis.getmNotiDesc()); 
        break; 
       case "noti_sms": 
        txt_noti.setText(actualNotis.getmNotiTitle()); 
        txt_noti_desc.setText(actualNotis.getmNotiDesc()); 
        break; 
       default: 
        break; 
      } 
     } 
    } 
} 

서버에서 JSON 응답

01,235 AdapterNotification.java입니다
{ 
    "notification": { 
    "noti_batch": [ 
     { 
     "title": "testtest", 
     "decription": "testtest" 
     } 
    ], 
    "noti_institute": [ 
     { 
     "title": "test", 
     "decription": "testtest", 
     "attach": "" 
     } 
    ], 
    "noti_fee": [ 
     { 
     "title": "test", 
     "decription": "test", 
     "attach": "" 
     } 
    ], 
    "noti_sms": [ 
     { 
     "title": "2016-11-03 00:00:00", 
     "decription": "" 
     } 
    ] 
    }, 
    "success": true 
} 

미리 감사드립니다.

답변

2

는, setAdapter onResponse() 내부의 서버 즉, 데이터를받은 후 또는 당신은 목록에

+0

감사 버디 데이터를 변경 한 후 어댑터를 통지해야한다! 건배...! –