i want to add another spinner on event of selecting the item in spinner

by rutu » Wed, 21 May 2008 12:18:12 GMT


Sponsored Links
 i fiends,
my program already contains an spinner i want that when a item is
selected it should open another spinner. i tried to do this but i have
to use another xml which opens the previous spinner and newer also.
so for first one i have to right the same code in the another file
again. can u suggest me ways how to do this without rewriting the code
for previous spinner again.

HERE IS THE CODE WHICH POPULATES FIRST SPINNER
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.colors,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{

public void onItemSelected(AdapterView parent, View v,
int position, long id) {
// TODO Auto-generated method stub

if(s1.getSelectedItem().toString().equals("yellow")){
openNewPage();
}

public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub

}

});

private void openNewPage() {
Intent i = new Intent(this,SpinnerNavigates.class);

startSubActivity(i, ACTIVITY_NAVIGATE);
}

XML CODE FOR THIS FILE
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<Spinner android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>

FOR ANOTHER FILE
<Button android:id="@+id/btnChange"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Changes"
/>


</LinearLayout>
IN SpinnerNavigates CLASS I WRITE THE CODE
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.navigate);


s1=(Spinner)findViewById(R.id.spinnerMain);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.colors,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);


s2=(Spinner)findViewById(R.id.spinnerNavigate);
ArrayAdapter<CharSequence> adapter2 =
ArrayAdapter.createFromResource(this, R.array.planets,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter2);


}
THEN FOR THIS XML CODE IS IN NAVIGATE.XML FILE
<LinearLayout xmlns:android="http://schemas



Other Threads

1. Problem with URL Camera

Hi there,
Im trying to test my app which shows an image from an IP Camera with
the ImageView object. It works properly on emulator but it doesnt on
G1. Any idea?

Thanks.

--~--~---------~--~----~------------~-------~--~----~

2. for image

how to get a different images on the screen by clicking next and
previous button on the screen and how i can disable next and prievous
button after all the images and at the first images

--~--~---------~--~----~------------~-------~--~----~

3. Messenger APIs in Adroid

4. Skype and VOIP services

5. Object Reference- R

6. Android Dev Phone - Failed to upload app using Eclipse (timeout)

7. Questions on sound processing