1. Download our Official Android App: Forums for Android!

Dynamic spinner based on the selected state

Discussion in 'Android Apps & Games' started by harshini, Jul 8, 2011.

  1. harshini

    harshini Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    5
    Joined:
    May 5, 2011

    May 5, 2011
    5
    0
    25
    i want to populate the spinner with respect to another spinner. Based on the selected item the other spinner should get the values dynamically.Any help will be appriciated....
     

    Advertisement

  2. harshini

    harshini Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    5
    Joined:
    May 5, 2011

    May 5, 2011
    5
    0
    25
    mport android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.widget.AdapterView.OnItemSelectedListener;

    public class FarmerFields extends Activity {

    public int mPos;
    public String mSelection;

    Spinner spinner,spinner1;
    protected ArrayAdapter<String> adapter,adapter1;
    public void onCreate(Bundle savedInstanceState)
    {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.farmerfields);

    String[] items = new String[] {"Text", "Number", "Audio"};
    spinner = (Spinner) findViewById(R.id.farmerfieldsspinner1);
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    final FarmerFields cntx = this;


    String[] items1 = new String[] {"Hindi", "English", "Telugu"};
    spinner1 = (Spinner) findViewById(R.id.farmerfieldsspinner2);
    adapter1 = new ArrayAdapter<String>(this,
    android.R.layout.simple_spinner_item, items1);
    adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(adapter1);
    {


    public void onItemSelected(AdapterView<?> arg0, View arg1,
    int arg2, long arg3) {
    // TODO Auto-generated method stub
    switch(arg2)
    {
    case 0:
    String[] items1 = new String[] {"Hindi", "English", "Telugu"};
    spinner1 = (Spinner) findViewById(R.id.farmerfieldsspinner2);
    adapter1 = new ArrayAdapter<String>(cntx,
    android.R.layout.simple_spinner_item, items1);
    adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(adapter1);
    break;

    }
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

    }});



    }

    }


    i have done in the following way but i am not getting the way which i need plzz any one help me.....
     

Share This Page

Loading...