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. Small screen devices cannot see my app even declared already in the manifest

Hello everyone,

 I have this problem regarding HTC Tatoo. I cannot see the app in the market 
using this phone but other phones can.

 I have already declared inside my manifest file that it is compatible and 
could run in this small device but still cannot see. Below is a snippet of my 
manifest file.

 <application
 ....
 </application>
 <uses-sdk android:minSdkVersion="3" />
 <supports-screens android:smallScreens="true" android:anyDensity="true"/>
 ....

Hoping for your great help.

Regards,

Brian



      

-- 

2. The application Settings(process com.android.settintgs) has stopped unexpectedly.while running bluetooth chat given sample appln

Ummm.... If there is no support for bluetooth in the emulator then it is not
possible to emulate bluetooth in the emulator.


----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------





> 

3. Masalah reply SMS

4. Ask Ganti ROM

5. Ada Yang Tau Cara Setting Yahoo Account pada "MAIL" nya HTC MAGIC ga?Sama Mau tanya Paket Data IM3

6. Please improve the soft keypad and add a password check box.

7. Power event