Slide show

Total Pageviews

Powered by Blogger.

Translate

Search This Blog

Pages

CREATE SPINNER IN ANDROID:-


JAVA CODE OF SPINNER CREATION:-


package com.spinner;

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.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class SpinnerDemoActivity extends Activity {
    Spinner spinner;
    String s[] = { "a", "b", "c", "d", "e", "f", "g" };

    /** Called when the activity is first created. */
    @SuppressWarnings("unchecked")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, s);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new A());
    }
   
    class A implements OnItemSelectedListener{

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            Toast.makeText(SpinnerDemoActivity.this, arg0.getItemAtPosition(arg2).toString(), 3000).show();
           
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
       
           
        }
       
    }
   
   
}


XML CODE :-


<?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_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner" />
  </LinearLayout>
MANIFEST FILE CODE:-
<?xml version="1.0" encoding="utf-8" ?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.spinner" android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="10" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".SpinnerDemoActivity" android:label="@string/app_name">
- <intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  </activity>
  </application>
  </manifest>
NOW RUN THE PROGRAM THE ENJOY IT. 

THANKS.

No comments:

vehicles

business

health