actually i am using 4 spinners...4th spinner must get filled depending on the selection made in 1st spinner?
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ADD8E6" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Group" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/group" android:layout_width="match_parent" android:layout_height="wrap_content" android:prompt="@string/group_prompt" android:entries="@array/group_names" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Year" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/year" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:prompt="@string/year_prompt" android:entries="@array/year_names" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Section" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/section" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:prompt="@string/section_prompt" android:entries="@array/section_names" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Subject" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/subject" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:prompt="@string/subject_prompt" /> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ADD8E6" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Group" android:textColor="#000000" android:textSize="30px" /> * <Spinner android:id="@+id/group"* * android:layout_width="match_parent"* * android:layout_height="wrap_content"* * * * android:prompt="@string/group_prompt"* * android:entries="@array/group_names"* * /> * <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Year" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/year" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:prompt="@string/year_prompt" android:entries="@array/year_names" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Section" android:textColor="#000000" android:textSize="30px" /> <Spinner android:id="@+id/section" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" android:prompt="@string/section_prompt" android:entries="@array/section_names" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Subject" android:textColor="#000000" android:textSize="30px" /> * <Spinner android:id="@+id/subject"* * android:layout_width="match_parent"* * android:layout_height="wrap_content"* * android:drawSelectorOnTop="true"* * android:prompt="@string/subject_prompt"* * * * />* </LinearLayout> This is the xml file..... spinner with id *subject* must get updated depending on the selection in the spinner with id *group*.... i am using getItem(position) to get the item selected in (1stspinner)spinner with id *group* *code:* import 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.AdapterView.OnItemSelectedListener; public class Trial1Activity extends Activity { /** Called when the activity is first created. */ String a1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner s1 = (Spinner) findViewById(R.id.group); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.group_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter); s1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView<?> parent, View view, int position, long id) { a1=(String)adapter.getItem(position); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); Spinner sub=(Spinner)findViewById(R.id.subject); // if(a1.equals("CSE")){ ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource( this, R.array.cse_1_subjects, android.R.layout.simple_spinner_item); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter1); /*else{ ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource( this, R.array.ece_1_subjects, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter2);}*/ } } import 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.AdapterView.OnItemSelectedListener; public class Trial1Activity extends Activity { /** Called when the activity is first created. */ String a1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner s1 = (Spinner) findViewById(R.id.group); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.group_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter); s1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView<?> parent, View view, int position, long id) { a1=(String)adapter.getItem(position); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); Spinner sub=(Spinner)findViewById(R.id.subject); // if(a1.equals("CSE")){ ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource( this, R.array.cse_1_subjects, android.R.layout.simple_spinner_item); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter1); /*else{ ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource( this, R.array.ece_1_subjects, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter2);}*/ } } import 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.AdapterView.OnItemSelectedListener; public class Trial1Activity extends Activity { /** Called when the activity is first created. */ String a1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner s1 = (Spinner) findViewById(R.id.group); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.group_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter); s1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView<?> parent, View view, int position, long id) { a1=(String)adapter.getItem(position); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); Spinner sub=(Spinner)findViewById(R.id.subject); // if(a1.equals("CSE")){ ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource( this, R.array.cse_1_subjects, android.R.layout.simple_spinner_item); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter1); /*else{ ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource( this, R.array.ece_1_subjects, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sub.setAdapter(adapter2);}*/ } } i am trying to use if...else logic to fill the spinner with differnt arrays depending on the selection made in 1st spinner(spinner with id *group)* but *when i use if loop* i am getting error *"application stopped working unexpectedly in android"* can u help me to implement this logic??? thanks in advance.. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

