-3

I want to implement one custom spinner for app where items will be countries name which will come from server. The name comes as ascending order which I want but I also want that India will come at first row of item.

 // for country spinner
    StringRequest sR = new StringRequest(Request.Method.GET, country_url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    ArrayList<String> arr = new ArrayList<String>(Arrays.asList(response.trim().split(",")));
                    arr.add(0, "Select Country");
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(EditDetails6.this, android.R.layout.simple_list_item_1, arr);
                    spinPCountryName.setAdapter(adapter);
Vikas Godiyal
  • 117
  • 3
  • 15

1 Answers1

3

Remove India from list, then add it to first position, Write following logic for this:

ArrayList<String> arr = new ArrayList<String>(Arrays.asList(response.trim().split(",")));
            for (int i = 0; i < arr.size(); i++) {
                if (arr.get(i).equals("India")) {
                    arr.remove(i);
                }
            }
            arr.add(0, "India");
            arr.add(0, "Select Country");
Divy Soni
  • 824
  • 9
  • 22