Spinner View - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul Spinner View, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.
Judul : Spinner View
link : Spinner View
Anda sekarang membaca artikel Spinner View dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/spinner-view.html
Judul : Spinner View
link : Spinner View
Spinner View
SPINNER VIEW Tutorial
Spinners are like drop down menu which provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.You can add a spinner to your layout with the Spinner object. You should usually do so in your XML layout with a <Spinner> element.
2.Copy the code to activity_main.xml in res/layout folder
1.Create Android Project as per the details listed in the table
Property name | Property value |
Project name | SRM_SpinnerViewTutorial |
Package name | in.ac.srmuniv.spinnerviewtutorial |
Activity name | MainActivity |
Layout xml name | activity_main |
2.Copy the code to activity_main.xml in res/layout folder
<?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"
>
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"/>
</LinearLayout>
2.Copy the code in MainActivity.java Activity
2.Copy the code in MainActivity.java Activity
package in.ac.srmuniv.spinnerviewtutorial;
importandroid.app.Activity;
import android.os.Bundle;
import android.view.View;
importandroid.widget.AdapterView;
importandroid.widget.ArrayAdapter;
importandroid.widget.Spinner;
importandroid.widget.Toast;
importandroid.widget.AdapterView.OnItemSelectedListener;
public class MainActivity extends Activity
{
String[] bond_films = {
"Dr.No",
"Man with Golden gun",
"You only Live twice",
"Live and Let die",
"Thunderball",
"License to Kill",
"From Russia with Love",
"Moonraker",
"Octopussy",
"A View to Kill",
"On Her Majesty Service",
"Golden Eye"
};
Spinner s1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, bond_films);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(newOnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2, long arg3)
{
int index = s1.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
"You have selected item : " + bond_films [index],Toast.LENGTH_SHORT).show(); }
public void onNothingSelected(AdapterView<?> arg0){}
});
}
}
3.The AndroidManifest.xml file need not be modified.
3.The AndroidManifest.xml file need not be modified.
4.Run the application on the Android emulator. Figure 1 shows the Spinner view in action.
Figure 3: The Spinner view with multiple choiceDemikianlah Artikel Spinner View
Sekianlah artikel Spinner View kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Spinner View dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/spinner-view.html
Spinner View
4/
5
Oleh
Unknown