recyclerview not showing data from json array after 7 items

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



recyclerview not showing data from json array after 7 items



I am using Recycler View with Cardview and showing data from JSON using Volley. It works proper on targetsdkversion 19 but not showing data after 7 list items when targetsdkversion is 26.


btnsend.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
chatLayout.setVisibility(View.VISIBLE);
subject = etsub.getText().toString();
details = etdetail.getText().toString();
if (etsub.getText().toString().equals(""))
Toast.makeText(getActivity(), "Enter subject", Toast.LENGTH_SHORT).show();
subj_layout.setError("Plese Enter Subject!");

else if (etdetail.getText().toString().equals(""))
detail_layout.setError("Please Enter Details!");

else
Log.d(TAG, "onClick:send ");
String url = "http://webapi.eduware.in/test/api/ParentsCommunication?StudentCurrentID=" + studentId.trim() + "&SchoolID=" + schoolid.trim() + "&CommunicationSubject=" + subject.trim() + "&CommunicationDetails=" + details.trim();
Log.d(TAG, "onClick: " + url);
Log.d(TAG, "fetchNotificationByVolley: url = " + url);

StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
Log.d(TAG, "onResponse: " + response);
try
JSONObject jobj = new JSONObject(response);
String status = jobj.getString("status");
if (status.equals("1"))
Toast.makeText(getActivity(), "Successfully added", Toast.LENGTH_SHORT).show();
getChatbyVolley();
txtnocomm.setVisibility(View.GONE);

else
Toast.makeText(getActivity(), "Data not added", Toast.LENGTH_SHORT).show();
chatLayout.setVisibility(View.VISIBLE);

catch (JSONException e)
e.printStackTrace();



, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.d(TAG, "onErrorResponse: " + error.getMessage());

)
@Override
protected Map<String, String> getParams() throws AuthFailureError
return null;

;

ApplicationController.getInstance().addToRequestQueue(stringRequest);

d.dismiss();


);



As shown in image, on click of Bottom right corner Add Button One custom dialog gets open and details of that dislogs edittext will be added to recyclerview by getChatbyVolley method.I am getting succesfully added but not display in list.But if targetsdkversion is 18 then it works perfect.


private void getChatbyVolley()
chatLayout.setVisibility(View.VISIBLE);
String url = "http://webapi.eduware.in/test/api/ParentsCommunication?StudentCurrentID="+studentId.trim();
final ArrayList<Chat> arrayList = new ArrayList<>();
final ArrayList<String> array = new ArrayList<>();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
@Override
public void onResponse(String response)
Log.d(TAG, "onResponse: " + response);
try
JSONObject jobj = new JSONObject(response);
String status = jobj.getString("status");
if(status.equals("1"))


JSONArray jsonArray = jobj.getJSONArray("data");

for(int i=0;i<jsonArray.length();i++)

JSONObject jsonObject = jsonArray.getJSONObject(i);
String date = jsonObject.getString("Date");
Log.d(TAG, "onResponse: "+date);
String separated = date.split("[T :]");
Log.d(TAG, "onResponse: splitted string0" + separated[0]);
Log.d(TAG, "onResponse: splitted string1" + separated[1]);
Log.d(TAG, "onResponse: splitted string2" + separated[2]);
Log.d(TAG, "onResponse: splitted string3" + separated[3]);
String time = separated[1] + ":" + separated[2];
Log.d(TAG, "onResponse: time is:::::::::::" + time);
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
DateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
String inputDateStr=separated[0];
Date date1 = inputFormat.parse(inputDateStr);
String outputDateStr = outputFormat.format(date1);
String detail = jsonObject.getString("CommunicationDetails");
Log.d(TAG, "onResponse: details========="+detail);
String pid = jsonObject.getString("ParentID");
Log.d(TAG, "onResponse: pid is*********"+pid);
array.add(pid);
Log.d(TAG, "onResponse: pid is*********"+array);
editor.putString("parent_id",pid);
editor.putString("parentid_array",array.toString());
editor.commit();
Chat c = new Chat();
c.setCommsubject(jsonObject.getString("CommunicationSubject"));
c.setCommdetails(jsonObject.getString("CommunicationDetails"));
c.setDate(outputDateStr);
c.setParentid(pid);
arrayList.add(c);
progress.dismiss();


chatAdapter = new ChatAdapter(getActivity(), arrayList);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(chatAdapter);
recyclerView.setHasFixedSize(true);
chatAdapter.notifyDataSetChanged();

Log.d(TAG, "onResponse: " + arrayList.size());
progress.dismiss();

else

Toast.makeText(context, "No communication available", Toast.LENGTH_SHORT).show();
progress.dismiss();
rlnocomm.setVisibility(View.VISIBLE);
btnadd.setVisibility(View.VISIBLE);

catch (JSONException e)
e.printStackTrace();
catch (ParseException e)
e.printStackTrace();



, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.d(TAG, "onErrorResponse: " + error.getMessage());

)
@Override
protected Map<String, String> getParams() throws AuthFailureError
return null;

;
ApplicationController.getInstance().addToRequestQueue(stringRequest);






can you post your code?
– Arbaz.in
Aug 14 at 6:07





1 Answer
1



Add this following line in your code. It works for me


recyclerview.setHasFixedSize(true);





Thank you for reply....But still It is not working for me when targetsdkversion is 26 in build.gradle (App level) file.I can add new item to recyclerview but its not displaying anything after 7 items. Please help me if anyone knows the solution.
– Kinjal
Aug 14 at 5:51





Send me your code to this email address. kbrahmaxatriya94@gmail.com
– Karan Israni
Aug 14 at 6:33





Use same Sdk version for all the dependencies try this compile 'com.android.support:recyclerview-v7:+' or change the sdk version to 25
– Karan Israni
Aug 14 at 12:24





I have made changes as u said but still not working..
– Kinjal
Aug 16 at 4:48






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS