Spinner data duplicated when list is clicked
<p>In Activity B there has a <code>spinner</code> where the data were get from <code>MySQL</code> (Table location).</p>

<p><strong>Activity B</strong></p>

<pre><code>private ArrayList&lt;String&gt; froms;
private JSONArray resultFrom;

public void addItemsOnFrom() {

    travelFrom = (Spinner) findViewById(R.id.travelFrom);
    StringRequest stringRequest = new StringRequest(Configs.FROM_URL,
            new Response.Listener&lt;String&gt;() {

                @Override
                public void onResponse(String response) {
                    JSONObject j = null;
                    try {
                        //Parsing the fetched Json String to JSON Object
                        j = new JSONObject(response);

                        //Storing the Array of JSON String to our JSON Array
                        resultFrom = j.getJSONArray(Configs.JSON_ARRAY);

                        //Calling method getStudents to get the students from the JSON Array
                        getFrom(resultFrom);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);
}

private void getFrom(JSONArray j) {
    //Traversing through all the items in the json array
    for (int i = 0; i &lt; j.length(); i++) {
        try {
            //Getting json object
            JSONObject json = j.getJSONObject(i);

            //Adding the name of the student to array list
            froms.add(json.getString(Configs.TAG_LOCATION));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    //Setting adapter to show the items in the spinner
    travelFrom.setAdapter(new ArrayAdapter&lt;String&gt;(Add_Details_Information.this, android.R.layout.simple_spinner_dropdown_item, froms));
}
</code></pre>

<p>When save <code>button</code> is clicked, it will return the selected value(OFFICE) to Activity A <code>listView</code>. And in Activity A, when the list is pressed, it will intent to Activity B. In this time, the spinner in Activity B will display the selected item first(OFFICE).</p>

<pre><code>**Table location**  // table location has 2 data
NONE 
OFFICE
</code></pre>

<p>Assume OFFICE is selected in B. When list is clicked, I want OFFICE display first in <code>spinner</code> B. </p>

<p>Code in <strong>Activity B</strong> for display OFFICE first.</p>

<pre><code>if(getIntent().getExtras()!=null)
{ 
    final String from = getIntent().getStringExtra("from");
    selectedItemFrom(from);
}
</code></pre>

<hr>

<pre><code>public void selectedItemFrom(final String value)// display  OFFICE first
{
    travelFrom = (Spinner) findViewById(R.id.travelFrom);
    StringRequest stringRequest = new StringRequest(Configs.FROM_URL,
            new Response.Listener&lt;String&gt;() {

                @Override
                public void onResponse(String response) {
                    JSONObject j = null;
                    try {
                        //Parsing the fetched Json String to JSON Object
                        j = new JSONObject(response);

                        //Storing the Array of JSON String to our JSON Array
                        result = j.getJSONArray(Configs.JSON_ARRAY);

                        //Calling method getStudents to get the students from the JSON Array
                        getFrom(result, value);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);
}

private void getFrom(JSONArray j, String value) {
    int position = 0;
    //Traversing through all the items in the json array
    for (int i = 0; i &lt; j.length(); i++) {
        try {
            //Getting json object
            JSONObject json = j.getJSONObject(i);
            //Adding the name of the student to array list
            froms.add(json.getString(Configs.TAG_LOCATION));
            if (froms.get(i).equalsIgnoreCase(value)) {

                position = i;
                //Toast.makeText(getApplicationContext(),position+"",Toast.LENGTH_LONG).show();
                break;
            }


        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    travelFrom.setAdapter(new ArrayAdapter&lt;String&gt;(Add_Details_Information.this, android.R.layout.simple_spinner_dropdown_item, froms));
    travelFrom.setSelection(position);
}
</code></pre>

<p>The OFFICE can display first, but the problem is when I checked the spinner B, it shows <code>NONE,OFFICE,NONE OFFICE</code> ..Why the spinner data will get duplicated ? Thanks</p>

<p>I think problem is in this line  <code>travelFrom.setAdapter(new ArrayAdapter&lt;String&gt;(Add_Details_Information.this, android.R.layout.simple_spinner_dropdown_item, froms));</code>...But how to solve??? Anyone?</p>

<p>And sometimes the spinner will display the selected item first but sometimes it will not...What are the better way to write?</p>

<p><strong>Edit</strong></p>

<pre><code>{"result":[{"name":"NONE"},{"name":"OFFICE"}]}
</code></pre>

<p>I put forms.clear in beginning of both getFrom method now. But the problem is when I select NONE and return to A, then goes to B again,the spinner now has NONE only...</p>