android related spinner
<p>How to perform android related spinner?</p>

<p>I have done it like this:</p>

<p>private Spinner ddlCountry, ddlCategory;</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    try {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pnplandingpage);

        ddlCountry = (Spinner) findViewById(R.id.ddlCountry);
        ddlCategory = (Spinner) findViewById(R.id.ddlCategory);

        // BindCountry(ddlCountry);

        // ddlCountry
        // .setOnItemSelectedListener(new OnCountryItemSelectedListener());

        // ddlCategory
        // .setOnItemSelectedListener(new
        // OnCategoryItemSelectedListener());

        // ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter
        // .createFromResource(this, R.array.Country_array,
        // android.R.layout.simple_spinner_item);
        // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // ddlCountry.setAdapter(adapter);

        ddlCountry.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView&lt;?&gt; parent, View pview,
                    int pos, long id) {

                final String[] array = new String[] { "Category",
                        "5 Miles", "10 Miles", "15 Miles", "20 Miles",
                        "25 Miles", };

                List&lt;String&gt; list = new ArrayList&lt;String&gt;();
                for (int i = 0; i &lt; array.length; i++) {
                    list.add(array[i]);
                }

                ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(
                        PNPLandingPage.this,
                        android.R.layout.simple_spinner_item, list);
                dataAdapter
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                ddlCategory.setAdapter(dataAdapter);

                Toast.makeText(
                        parent.getContext(),
                        "The Country is "
                                + parent.getItemAtPosition(pos).toString(),
                        Toast.LENGTH_LONG).show();
            }

            public void onNothingSelected(AdapterView parent) {
                // Do nothing.
                ddlCategory.setAdapter(null);

            }
        });

        // BindCategory(ddlCategory);

        // ddlCategory
        // .setOnItemSelectedListener(new OnCategoryItemSelectedListener());

        ddlCategory.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView&lt;?&gt; parent, View pview,
                    int pos, long id) {

                final String[] array = new String[] { "Country",
                        "Country1", "Country2", "Country3", "Country4",
                        "Country5", };


                List&lt;String&gt; list = new ArrayList&lt;String&gt;();
                for (int i = 0; i &lt; array.length; i++) {
                    list.add(array[i]);
                }

                ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(
                        PNPLandingPage.this,
                        android.R.layout.simple_spinner_item, list);
                dataAdapter
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                ddlCountry.setAdapter(dataAdapter);

                // ddlCategory
                // .setOnItemSelectedListener(new
                // OnCategoryItemSelectedListener());

                Toast.makeText(
                        parent.getContext(),
                        "The Category is "
                                + parent.getItemAtPosition(pos).toString(),
                        Toast.LENGTH_LONG).show();
            }

            public void onNothingSelected(AdapterView parent) {
                // Do nothing.
                ddlCountry.setAdapter(null);

            }
        });

    } catch (Exception ex) {
        Toast.makeText(getApplication(), "EXCEPTION :" + ex, 1000);
    }
}
</code></pre>

<p>But the Toast gets fired every time, i.e the onItemSelected gets repeated. what am i doing mistake..</p>
