-2

i customized android AlertDialog to have simple ListView into that and i'm using HashMap data for that,

getProvince method return 30 record and i save that into

ArrayList<HashMap<String, String>> provinceHashMap = new ArrayList<>();

getProvince:

private void getProvince() {
        String                  province = Provinces.getProvinceData();
        HashMap<String, String> salam;

        try {
            JSONObject data    = new JSONObject(province);
            JSONArray  RECORDS = data.getJSONArray("RECORDS");

            for (int p = 0; p < RECORDS.length(); p++) {
                JSONObject object = RECORDS.getJSONObject(p);
                salam = new HashMap<>();
                salam.put("id", object.getString("id"));
                salam.put("name", object.getString("name"));
                provinceHashMap.add(salam);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

now when i use that to show items my listview have empty data:

private void showStatePopup() {
    AlertDialog.Builder mBuilder = new AlertDialog.Builder(ActivityGetPersonInfo.this, R.style.PopupTheme);
    final View          mView    = getLayoutInflater().inflate(R.layout.popup_select_state_and_city, null);
    mBuilder.setView(mView);
    final AlertDialog dialog = mBuilder.create();
    dialog.setCanceledOnTouchOutside(false);

    listView = (ListView) mView.findViewById(R.id.list);

    SimpleAdapter adapter = new SimpleAdapter(context, provinceHashMap, R.layout.invite_list_view,
            new String[]{"name"}, new int[]{R.id.inviteTextView});

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {

            int    itemPosition = position;
            String itemValue    = (String) listView.getItemAtPosition(position);
            ((TextView) findViewById(R.id.tv_ostan)).setText(itemValue);
            dialog.dismiss();
        }

    });

    dialog.getWindow().setDimAmount(0.8f);
    dialog.show();
}

getProvince(); called from onCreate()

UPDATE:

Provinces.getProvinceData(); return this value:

public static String provinceData = "{\"RECORDS\":[{\"id\":1,\"name\":\"آذربایجان شرقی\"},{\"id\":2,\"name\":\"آذربایجان غربی\"},{\"id\":3,\"name\":\"اردبیل\"},{\"id\":4,\"name\":\"اصفهان\"},{\"id\":5,\"name\":\"ایلام\"},{\"id\":6,\"name\":\"بوشهر\"},{\"id\":7,\"name\":\"تهران\"},{\"id\":8,\"name\":\"چهارمحال بختیاری\"},{\"id\":9,\"name\":\"خراسان جنوبی\"},{\"id\":10,\"name\":\"خراسان رضوی\"},{\"id\":11,\"name\":\"خراسان شمالی\"},{\"id\":12,\"name\":\"خوزستان\"},{\"id\":13,\"name\":\"زنجان\"},{\"id\":14,\"name\":\"سمنان\"},{\"id\":15,\"name\":\"سیستان و بلوچستان\"},{\"id\":16,\"name\":\"فارس\"},{\"id\":17,\"name\":\"قزوین\"},{\"id\":18,\"name\":\"قم\"},{\"id\":19,\"name\":\"کرج\"},{\"id\":20,\"name\":\"كردستان\"},{\"id\":21,\"name\":\"كرمان\"},{\"id\":22,\"name\":\"كرمانشاه\"},{\"id\":23,\"name\":\"كهكیلویه و بویراحمد\"},{\"id\":24,\"name\":\"گلستان\"},{\"id\":25,\"name\":\"گیلان\"},{\"id\":26,\"name\":\"لرستان\"},{\"id\":27,\"name\":\"مازندران\"},{\"id\":28,\"name\":\"مركزی\"},{\"id\":29,\"name\":\"هرمزگان\"},{\"id\":30,\"name\":\"همدان\"},{\"id\":31,\"name\":\"یزد\"}]}";
9
  • what do u want to display in the list?? Commented Jul 3, 2017 at 5:57
  • From where method showStatePopup() called? can you please post full class code? Commented Jul 3, 2017 at 6:04
  • @AvinashRoy displaying name values from json keys which its saved into hashMap Commented Jul 3, 2017 at 6:06
  • @FAT after click on some widget on view i'm calling showStatePopup() method Commented Jul 3, 2017 at 6:07
  • u cannot push an array list of hashmaps into the adapter just like that Commented Jul 3, 2017 at 6:08

1 Answer 1

2

try to add after set adapter

        adapter.notifyDataSetChanged();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.