How to remain the "Select One" string when adding Items in Spinner
<p>I have a question that, I have two spinners, both spinners are filled by data after JSON parsing, presently when we call that particular Activity (Which opens after Parsing, in which both Spinners are held), all data are shown in first Spinner and in second spinner according to First Spinner's Selection but we want that when we call that Activity it firstly shows Select in all spinners, and when we click on them then it shows its values. How can we acheive that. Please help me out about this problem. </p>

<p>Thanks in advance.</p>

<p><strong>Code:</strong></p>

<pre><code>package com.equinix.android.sitevisit;


import java.util.ArrayList;
import java.util.Calendar;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;

import com.equinix.android.adapter.SiteVisit_CagesAdapter;
import com.equinix.android.adapter.SiteVisit_IBXAdapter;
import com.equinix.android.common.LoginScreen;
import com.equinix.android.common.MenuScreen;
import com.equinix.android.common.R;
import com.equinix.android.parsing.Parse_Json;
import com.equinix.android.servicecall.Service_Call;

public class Site_Visit_Details extends Activity {
    /** Called when the activity is first created. */

     ImageButton _siteVisit_Home, _siteVisit_Logout, _siteVisit_AddVisitor, _siteVisit_StartDateButton, _siteVisit_EndDateButton, _siteVisit_Next, _siteVisit_CheckBox;
     EditText _siteVisit_StartDate, _siteVisit_EndDate, _siteVisit_AdditionalInfo;
     Spinner _siteVisit_IBX, _siteVisit_Cage;
     ArrayAdapter statusAdapter;
    private int mYear;
    private int mMonth;
    private int mDay;
    private int flagValue;
    static final int DATE_DIALOG_ID = 0;
    public static ArrayList&lt;String&gt; cage_Id = new ArrayList&lt;String&gt;();
    public static ArrayList&lt;String&gt; cage_Name = new ArrayList&lt;String&gt;();
    public static ArrayList&lt;String&gt; cage_NaturalKey = new ArrayList&lt;String&gt;();
    public static boolean flag_cages = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.site_visit_details);
        _siteVisit_Home = (ImageButton)findViewById(R.id.home);
        _siteVisit_Logout = (ImageButton)findViewById(R.id.logout);
        _siteVisit_AddVisitor = (ImageButton)findViewById(R.id.addVisitorImageButton);
        _siteVisit_StartDateButton = (ImageButton)findViewById(R.id.startDateImageButton);
        _siteVisit_EndDateButton = (ImageButton)findViewById(R.id.endDateImageButton);
        _siteVisit_Next = (ImageButton)findViewById(R.id.nextImageButton);
        _siteVisit_CheckBox =(ImageButton)findViewById(R.id.checkBox);

        _siteVisit_StartDate = (EditText)findViewById(R.id.startDateEditText);
        _siteVisit_EndDate = (EditText)findViewById(R.id.endDateEditText);
        _siteVisit_AdditionalInfo = (EditText)findViewById(R.id.additionalInformationEditText);

        _siteVisit_IBX = (Spinner)findViewById(R.id.ibxSpinner);
        _siteVisit_Cage = (Spinner)findViewById(R.id.cageSpinner);

        statusAdapter = ArrayAdapter.createFromResource( this, R.array.options , android.R.layout.simple_spinner_item);//Sets an status adapter
        statusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);//Displays drop down spinner
        //statusAdapter.add(LoginScreen.name);
        SiteVisit_IBXAdapter adapter = new SiteVisit_IBXAdapter(LoginScreen.name, this);
        _siteVisit_IBX.setAdapter(adapter);
        _siteVisit_Cage.setAdapter(statusAdapter);

        _siteVisit_Next.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

            Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_Login.class);
            intent.putExtra("IBXName", _siteVisit_IBX.getSelectedItem().toString());
            intent.putExtra("CagesName", _siteVisit_Cage.getSelectedItem().toString());
            intent.putExtra("StartDate", _siteVisit_StartDate.getText().toString());
            intent.putExtra("EndDate", _siteVisit_EndDate.getText().toString());
            startActivity(intent);

            }
        });

        _siteVisit_IBX.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            /**
             * Called when a new item was selected (in the Spinner)
             */
            public void onItemSelected(AdapterView&lt;?&gt; parent,
                View view, int pos, long id) {
                try{
                    arrayList_clear();

                HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/cages");
                StringEntity se = new StringEntity("{\"ibx\":{\"credentials\":{\"username\":\"mobileuser1\",\"password\":\"welcome1\"},\"userkey\":\"68782\",\"permissionCode\":\"PLACE_BASIC_SERVICES\",\"id\":\""+LoginScreen.id.get(pos)+"\",\"name\":\""+LoginScreen.name.get(pos)+"\",\"naturalKey\":\""+LoginScreen.naturalKey.get(pos)+"\"}}");
                final Service_Call obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);
            /*  String json_Response = obj.call_Service();
                new Parse_Json(json_Response).parse_Cages();*/
                    /*SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);

                    _siteVisit_Cage.setAdapter(adapter);*/

                    final ProgressDialog dialog = ProgressDialog.show(Site_Visit_Details.this, "   EQUINIX                   ", "Loading....   ", true);

                    final Handler handler = new Handler() {



                       public void handleMessage(Message msg) {

                           SiteVisit_CagesAdapter adapter = new SiteVisit_CagesAdapter(Site_Visit_Details.cage_Name, Site_Visit_Details.this);

                        _siteVisit_Cage.setAdapter(adapter);
                               dialog.dismiss();


                          }
                       };

                       final Thread checkUpdate = new Thread() {

                           public void run() {


                               String json_Response = obj.call_Service();
                            new Parse_Json(json_Response).parse_Cages();
                               handler.sendEmptyMessage(0);
                           }
                       };
                       checkUpdate.start();
                }catch(Exception e)
                {
                    e.printStackTrace();
                }
            }

            private void arrayList_clear() {
                Site_Visit_Details.cage_Id.clear();
                Site_Visit_Details.cage_Name.clear();
                Site_Visit_Details.cage_NaturalKey.clear();

            }

            public void onNothingSelected(AdapterView parent) {
              // Do nothing.
            }
        });

        _siteVisit_StartDateButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                flagValue = 0;
                showDialog(DATE_DIALOG_ID);


            }
        });

        _siteVisit_EndDateButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                flagValue = 1;
                showDialog(DATE_DIALOG_ID);

            }
        });

        _siteVisit_AddVisitor.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(Site_Visit_Details.this, Site_Visit_AddVisitor.class);
                startActivity(intent);

            }
        });

        _siteVisit_CheckBox.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                _siteVisit_CheckBox.setBackgroundResource(R.drawable.check_box_checked);

            }
        });


        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);


    }


    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, 
                                  int monthOfYear, int dayOfMonth) {
                mYear = year;
                mMonth = monthOfYear;
                mDay = dayOfMonth;
                updateDisplay(flagValue);
            }
        };

    private void updateDisplay(int flag) {
        if(flag==0){
        _siteVisit_StartDate.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
        }
        else{
            _siteVisit_EndDate.setText(
                    new StringBuilder()
                            // Month is 0 based so add 1
                            .append(mMonth + 1).append("-")
                            .append(mDay).append("-")
                            .append(mYear).append(" "));
        }
    }


    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this,
                        mDateSetListener,
                        mYear, mMonth, mDay);

        }
        return null;
    }
}
</code></pre>
