I have a main Fragment and a dialog box. And when you click on OK on the ListView dialog box on the main fragment, it should be filtered out.

The code that runs when you click:

if (response != null && !response.equals("null\n")) { MainFragment.filterPage++; try { JSONArray object = new JSONArray(response); for (int i = 0; i < object.length(); i++) { JSONObject finalObject = object.getJSONObject(i); VacancyModel model = new VacancyModel(); model.setId(Integer.parseInt(finalObject.getString(JSONKeyNames.ATTRIBUTE_ID))); model.setHeader(finalObject.getString(JSONKeyNames.ATTRIBUTE_HEADER)); model.setProfession(finalObject.getString(JSONKeyNames.ATTRIBUTE_PROFESSION)); vacancyModelList.add(model); } activity.runOnUiThread(new Runnable() { @Override public void run() { MainVacancyAdapter adapter = new MainVacancyAdapter(activity.getApplicationContext(), R.layout.main_row_layout, vacancyModelList); adapter.notifyDataSetChanged(); Toast.makeText(activity.getApplicationContext(), "Загрузились вакансии по фильтру!", Toast.LENGTH_SHORT).show(); } }); } catch (JSONException e) { e.printStackTrace(); } } 

Everything works correctly, it is sent and the adapter receives new data. Only the list does not update

What could be the problem?

  • And where is the adapter binding to the listview? - Crazy
  • Binding in the Main Fragment - DevOma

1 answer 1

You create a new adapter object and call .notifyDataSetChanged() from it.

Either install this new adapter for your ListView , or call .notifyDataSetChanged() for an adapter that is already installed.

  • ListView declared static and set MainFragment.listView.setAdapter (adapter); Earned, thanks! - DevOma