1

I use productsList.add(p)...by using this the entire listview gets updated with the value of p (where p is an object) ... Instead i want to change only a particular row in listview depending on the position... below is the code fetching data from mysql.....please do help

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, response.toString());

                        try {

                  JSONArray products = response.getJSONArray("products");

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

                  JSONObject product = (JSONObject) products.get(i);

                  String Id = product.getString("id");
                  String name = product.getString("name");                                                              
                  String description = product.getString("description");
                  Double mrp = Double.valueOf(product.getString("mrp"));
                  Double price = Double.valueOf(product.getString("price"));
                  String image = product.getString("image");
                  String sku = product.getString("sku");
                  Product p = new Product(id, name, description, mrp, price, 
                                     image, sku);
                    productsList.add(p);
                    notifyDataSetChanged();
                                }
                    }
              };

2 Answers2

0

I think that you not execute the notifyDataSetChanged(); from the adapter, like this listviewadapter.notifyDataSetChanged();

Pablo DbSys
  • 532
  • 1
  • 7
  • 17
  • Its like this Question https://stackoverflow.com/questions/13427069/calling-notifydatasetchanged-from-inside-adapter-fails – Pablo DbSys Jan 04 '18 at 18:44
0

ArrayAdapter doesn't provide the option to refresh only the specific row. You have to use RecylerView and RecyclerView.Adapter, It will provide an option to update specific row, notifyItemChanged(int position, Object payload)

You can refer the following link for example https://stackoverflow.com/a/33968779/2470770

lib4backer
  • 3,337
  • 3
  • 18
  • 16