Slide show

Total Pageviews

Powered by Blogger.

Translate

Search This Blog

Pages

ARRAY ADAPTER WITH SPINNER


JAVA CODE OF  ARRAY ADAPTER WITH SPINNER:-


package com.example.arraylistwithadapter;

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

public class MainActivity extends Activity implements OnItemSelectedListener {

 TextView selection;
 Spinner spin;
 String[] items = { "bangladesh", "bangla", "bd", "australia", "japan",
   "china", "indiaA", "indiaC" };

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  selection = (TextView) findViewById(R.id.selection);

  Spinner spin = (Spinner) findViewById(R.id.spinner);

 
  spin.setOnItemSelectedListener(this);

  ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
    android.R.layout.simple_spinner_item, items);

  spin.setAdapter(aa);
 }

 public void onItemSelected(AdapterView<?> parent, View v, int position,
   long id) {
  // TODO Auto-generated method stub
  selection.setText(items[position]);

 }

 public void onNothingSelected(AdapterView<?> arg0) {
  // TODO Auto-generated method stub
  selection.setText("");

 }
}


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:id="@+id/selection"
      android:layout_width="fill_parent"
  android:layout_height="wrap_content" />

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

</LinearLayout>


MANIFEST FILE CODE:-


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.arraylistwithadapter"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.arraylistwithadapter.MainActivity"
            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>


STRING FILE CODE :-


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Arraylistwithadapter</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>

</resources>





No comments:

vehicles

business

health