Translate To Your Own Langauge

Spinner Android Example



Spinner control is sometimes confused with the circular progress bar in Android. Sometimes when it is asked to the fresher about spinner, they generally answer it wrong. Note that Spinner is just like a DropDown. This control is used when we have a lot of entries available but we want user to select only one among them. So here we will try to implement the Spinner into our Android project. Follow these Steps:

Step 1:

Drag and drop the Spinner Control from the “Form widgets” provided in the palette or just copy and paste the following code into .xml file.
<Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="61dp" />

Step 2:

                To add items into spinner, Go to res/values/string.xml and add the following code into your string.xml file.
<!-- for spinner -->
    <string-array name="choice">
        <item >jellybean</item>
        <item >Gigerbread</item>
        <item >laddu</item>
       
    </string-array>
               

Step 3:

                Now go to Graphical layout of activity_main.xml  
·         Right click on spinner
·         Select Edit enteries
·         From array, select choice (Name given to string-array in string.xml file)
·         Click OK.
OR
Just add the following code into <string> tag
        android:entries="@array/choice"

Step 4:

Your spinner has now all those items which are added by you in the <string-array>.

Adding Functionality to Spinner

Now if you want to know that which item has been selected by the user then you have to work on .java file. Follow these steps;
·        Create the object of Spinner class i.e
Spinner sp;


·        Initialize the object inside oncreate method i.e
      
sp=(Spinner)findViewById(R.id.spinner1);


·         Add SetonselectedItemListener

       sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

              @Override
              public void onItemSelected(AdapterView<?> arg0, View v,
                           int i, long l) {
                     // TODO Auto-generated method stub
                     // to get the value of selected item
                     String str=((TextView)v).getText().toString();
//Display msg       
                     Toast.makeText(getApplicationContext(),str , 0).show();             
              }

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


·        Run your project on your device or virtual device.

13 Responses to “Spinner Android Example”

Resul said...
27 September 2023 at 16:46

https://bayanlarsitesi.com/
Cihangir
Heybeliada
Yalova
Adana
UHTC6B


Waynee said...
8 October 2023 at 16:41

görüntülü show
ücretlishow
KGCFLS


NebulaSorcererXYOLG1 said...
21 October 2023 at 14:14

Mersin Lojistik
Amasya Lojistik
Kayseri Lojistik
Kırklareli Lojistik
Erzurum Lojistik
1NX3


21F41Alena95F83 said...
6 November 2023 at 04:17

7D280
Samsun Parça Eşya Taşıma
Bilecik Evden Eve Nakliyat
Ağrı Evden Eve Nakliyat
Bursa Parça Eşya Taşıma
Bartın Evden Eve Nakliyat


7788DKolten75F3B said...
9 November 2023 at 21:53

40812
Balıkesir Parça Eşya Taşıma
İstanbul Evden Eve Nakliyat
Bingöl Parça Eşya Taşıma
Burdur Lojistik
Pursaklar Boya Ustası
Şırnak Şehir İçi Nakliyat
Van Şehir İçi Nakliyat
Erzurum Evden Eve Nakliyat
Çerkezköy Yol Yardım


049B5Jeramiah95F9F said...
11 November 2023 at 17:35

3598D
Zonguldak Evden Eve Nakliyat
Osmaniye Lojistik
Yalova Şehirler Arası Nakliyat
Aksaray Lojistik
Kocaeli Şehir İçi Nakliyat
Iğdır Şehirler Arası Nakliyat
Yozgat Lojistik
Adana Şehirler Arası Nakliyat
Hexa Coin Hangi Borsada


86130Tommy4601F said...
16 November 2023 at 07:49

09C77
Denizli Parça Eşya Taşıma
Sakarya Parça Eşya Taşıma
Aydın Şehir İçi Nakliyat
Karabük Evden Eve Nakliyat
Ordu Şehir İçi Nakliyat
Malatya Lojistik
Niğde Şehirler Arası Nakliyat
Ünye Oto Boya
Yozgat Evden Eve Nakliyat


7B469Alessia5BAB7 said...
1 December 2023 at 21:59

4EDF9
binance komisyon indirimi %20


B3DF1Cataleya96CEC said...
5 December 2023 at 23:06

BF9EA
binance komisyon indirimi %20


548EFDerrick24D87 said...
22 December 2023 at 18:10

1136C
diyarbakır ücretsiz sohbet uygulamaları
sohbet uygulamaları
çanakkale sohbet muhabbet
ücretsiz görüntülü sohbet
görüntülü sohbet kadınlarla
denizli parasız sohbet
tunceli sohbet chat
mardin yabancı görüntülü sohbet
adana görüntülü sohbet yabancı


6FD73Jordan1A21E said...
6 January 2024 at 17:39

80489
Bone Coin Hangi Borsada
Threads Yeniden Paylaş Hilesi
Dxgm Coin Hangi Borsada
Clysterum Coin Hangi Borsada
Twitter Retweet Satın Al
Bitcoin Kazanma
Trovo Takipçi Hilesi
Likee App Takipçi Satın Al
Binance Referans Kodu


6E022DB33FMakennaD7C8ABE77E said...
11 October 2024 at 06:16

C64BC689B4
skype şov


971154A220HugoB4C2A13C16 said...
21 November 2024 at 16:16

002A7768D9
emojicoin
rocketpool stake
aethir
medi finance
mitosis
galxe stake
emoji coin
moonbeam
dymension


Post a Comment

Comment your feedback for the post. You can also ask your queries regarding android.

Blogger Widgets
All Rights Reserved Android Tutorials | Designed by: Deepak Anand