SOURCE CODE [main.xml] is

<?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" >

<TextView  android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"  />

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

</LinearLayout>


SOURCE CODE [SpinnerExample.java] is


package com.SpinnerExample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerExample extends Activity
{
                Spinner sp;
                ArrayAdapter<String> adapter;
                String numbers[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN",
                                                "EIGHT", "NINE", "TEN" };

                public void onCreate(Bundle savedInstanceState)
{

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

                                sp = (Spinner) findViewById(R.id.spinner1);

                                adapter = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item, numbers);
                                sp.setAdapter(adapter);

                                sp.setOnItemSelectedListener(new
OnItemSelectedListener()
{
                                                public void
onItemSelected(AdapterView<?> arg0, View arg1,

                int arg2, long arg3)
{
Toast.makeText(getBaseContext(), sp.getSelectedItem().toString(),
Toast.LENGTH_LONG).show();
                                                }
                                                public void
onNothingSelected(AdapterView<?> arg0)
{
                                                                // TODO
Auto-generated method stub
                                                }
});
                }
}



On Thu, Mar 1, 2012 at 6:01 PM, vivek elangovan
<[email protected]>wrote:

> ok i will try that one ,if u any samples also pls send me
>
>
> On Thu, Mar 1, 2012 at 5:18 PM, arun kumar <[email protected]> wrote:
>
>> same you create another spinner and declare another string array and get
>> the position value and assign to string and set to textbox thats it.
>>
>>
>> On Thu, Mar 1, 2012 at 5:12 PM, vivek elangovan <
>> [email protected]> wrote:
>>
>>> Hi Arun,
>>>                How will i set the name for the next text field
>>>
>>>
>>> On Thu, Mar 1, 2012 at 4:44 PM, arun kumar <[email protected]>wrote:
>>>
>>>> spinner1 = (Spinner)this.findViewById(R.id.spinner1);
>>>> final String[] groupes = new String[] {"A", "B", "C", "D", "E", "F",
>>>> "G", "H"};
>>>> ArrayAdapter<CharSequence> featuresAdapter = new ArrayAdapter<
>>>> CharSequence>(this, android.R.layout.simple_spinner_item, new ArrayList
>>>> <CharSequence>());
>>>> featuresAdapter.setDropDownViewResource(android.R.layout.
>>>> simple_spinner_dropdown_item);
>>>> spinner1.setAdapter(featuresAdapter);
>>>> for (String s : groupes) featuresAdapter.add(s);
>>>>
>>>> spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
>>>>      public void onItemSelected(AdapterView<?> arg0, View arg1, intposition
>>>> , long id) {
>>>>          // Here go your instructions when the user chose something
>>>>          Toast.makeText(getBaseContext(), groupes[position], 0).show();
>>>>
>>>>      }
>>>>      public void onNothingSelected(AdapterView<?> arg0) { }
>>>> });
>>>>
>>>>
>>>> On Thu, Mar 1, 2012 at 4:34 PM, vivek elangovan <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi members,
>>>>>                  Using spinner i display list of details what i need
>>>>> to do is after selecting the item using spinner i need to display a data 
>>>>> in
>>>>> text field.
>>>>> For eg : If i m selecting state from spinner i need to display country
>>>>> name in next field.
>>>>>
>>>>> - Vivek Elangovan
>>>>>
>>>>> --
>>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> WITH REGARDS
>>>> ARUN KUMAR P D
>>>> +91-9663471079
>>>>
>>>> --
>>>> 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
>>>>
>>>
>>>
>>>
>>> --
>>> thanks & regards,
>>> Vivek . E
>>> 9841841099
>>>
>>>
>>> --
>>> 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
>>>
>>
>>
>>
>> --
>> WITH REGARDS
>> ARUN KUMAR P D
>> +91-9663471079
>>
>> --
>> 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
>>
>
>
>
> --
> thanks & regards,
> Vivek . E
> 9841841099
>
> --
> 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
>



-- 
WITH REGARDS
ARUN KUMAR P D
+91-9663471079

-- 
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

Reply via email to