click on spinner item and call asynctask of second spinner list item
<p>I am developing an app in which i need to fill spinner from one <code>webservice</code> and there are second spinner are also exist which fill after select first spinner item. second(spinner B) is depend on spinner A. i got list for A but problem with b spinner.</p>

<p>my basic requirement is when i select the item of spinner "A" it will load all item of Spinner "b" 
<strong>here is code ::</strong></p>

<pre><code>package com.CaribPay;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.Setting.CustomParser;

public class Register2 extends Activity implements OnItemClickListener {
    private Button BtnReg2Next;
    private EditText EdtxReg2Streetadd1,
                     EdtxReg2Streetadd2,
                     EdtxReg2City,
                     EdtxReg2Zipcode;

    private Spinner 
                    SpnrReg2Contry,
                    SpnrReg2Agent,
                    SpnrReg2State,
                    SpnrReg2PrimaryCurr,
                    SpnrReg2SecondaryCurr;

    private CustomParser cstParsr = new CustomParser();

    private String[] Regstrationstep1;
    private String[] strCountry,strProvince;
    private String[] Primarysecondarycur;
    private int globPosition;
    private String strSelecteccontry;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register2);
        GetDataFromLastPage();

        new FillSpinnerTask().execute();



    }

      private class FillSpinnerTask  extends AsyncTask&lt;Void, Void, Void&gt; {
            private ProgressDialog dialog = new ProgressDialog(
                    Register2.this);

            @Override
            protected void onPreExecute() {
                this.dialog.setMessage(getString(R.string.MsgPleasewait));
                this.dialog.show();
                this.dialog.setCancelable(false);
                // put your code which preload with processDialog

            }

            @Override
            protected Void doInBackground(Void... arg0) {
                // put your code here
                strCountry = cstParsr.LoadCountriesForMobApp(getApplicationContext());

                return null;
            }

            @Override
            protected void onPostExecute(final Void unused) {
                if (this.dialog.isShowing()) {
                    try {
                        this.dialog.dismiss();
                        this.dialog = null;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if(strCountry != null)
                    {
                        for(int i=0;i&lt;strCountry.length;i++)
                        {
                            Log.i("TAG","strCountry"+strCountry[i]);
                        }

                    }
                    FillView();

                }
            }
        }


    private void FillView() {

        BtnReg2Next = (Button)findViewById(R.id.BtnReg2Next);
        EdtxReg2Streetadd1 = (EditText)findViewById(R.id.EdtxReg2Streetadd1);
        EdtxReg2Streetadd2= (EditText)findViewById(R.id.EdtxReg2Streetadd2);
        EdtxReg2City  = (EditText)findViewById(R.id.EdtxReg2City);
        EdtxReg2Zipcode =  (EditText)findViewById(R.id.EdtxReg2Zipcode);

        SpnrReg2Contry = (Spinner)findViewById(R.id.SpnrReg2Contry); 
        SpnrReg2Agent = (Spinner)findViewById(R.id.SpnrReg2Agent);
        SpnrReg2State = (Spinner)findViewById(R.id.SpnrReg2State);
        SpnrReg2PrimaryCurr = (Spinner)findViewById(R.id.SpnrReg2PrimaryCurr);
        SpnrReg2SecondaryCurr= (Spinner)findViewById(R.id.SpnrReg2SecondaryCurr);


        if(strCountry != null)
        {
            ArrayAdapter languagelist = new ArrayAdapter(
                Register2.this,
                android.R.layout.simple_spinner_item, 
                strCountry);

            languagelist.setDropDownViewResource(
                android.R.layout.simple_spinner_dropdown_item);
            SpnrReg2Contry.setAdapter(languagelist);
        }


        SpnrReg2Contry.setOnItemSelectedListener(new OnItemSelectedListener() 
           {
                public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                        int position, long arg3) 
                {   

                        strSelecteccontry = strCountry[position];
                        new FillProvinceSpinnerTask().execute();

                }

                @Override
                public void onNothingSelected(AdapterView&lt;?&gt; arg0) {

                }


            });

        /*SpnrReg2State.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(strProvince == null)
                {
                new FillProvinceSpinnerTask().execute();
                }
                return true;
            }
        });*/



        BtnReg2Next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(EdtxReg2Streetadd1.getText().toString().equalsIgnoreCase("")|
                     EdtxReg2Streetadd2.getText().toString().equalsIgnoreCase("")|
                     EdtxReg2City.getText().toString().equalsIgnoreCase("")|
                     EdtxReg2Zipcode.getText().toString().equalsIgnoreCase(""))
                {
                    Toast.makeText(getApplication(),getString(R.string.nullmessage),Toast.LENGTH_LONG).show();
                }else
                {
                     Intent Registration2 = new Intent(Register2.this,Register3.class);
                     startActivity(Registration2);
                     finish();
                }


            }
        });
    }

    private void GetDataFromLastPage() {
        // TODO Auto-generated method stub
        Intent intent = getIntent();

        Regstrationstep1 = new String[9];
        Regstrationstep1 = intent.getStringArrayExtra("Regstrationstep1");


    }
    @Override
    public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int Pos, long arg3) {
        // TODO Auto-generated method stub
    }

    private class FillProvinceSpinnerTask  extends AsyncTask&lt;Void, Void, Void&gt; {
        private ProgressDialog dialog = new ProgressDialog(
                Register2.this);

        @Override
        protected void onPreExecute() {
            this.dialog.setMessage(getString(R.string.MsgPleasewait));
            this.dialog.show();
            this.dialog.setCancelable(false);
            // put your code which preload with processDialog

        }

        @Override
        protected Void doInBackground(Void... arg0) {
            // put your code here
            strProvince = cstParsr.LoadProvinceFromCountryForMobApp(getApplicationContext(),strSelecteccontry);


            return null;
        }

        @Override
        protected void onPostExecute(final Void unused) {
            if (this.dialog.isShowing()) {
                try {
                    this.dialog.dismiss();
                    this.dialog = null;
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if(strProvince != null)
                {


                    Primarysecondarycur = strProvince[0].split("~");
                    strProvince[0] = "Please Select a State";
                ArrayAdapter languagelist = new ArrayAdapter(
                        Register2.this,
                        android.R.layout.simple_spinner_item, 
                        strProvince);

                languagelist.setDropDownViewResource(
                   android.R.layout.simple_spinner_dropdown_item);
                SpnrReg2State.setAdapter(languagelist);


                }
            }
        }
    }


}
</code></pre>
