Skip to main content

Spinner Combolist in Android Tutorial

Spinner Combolist in Android Tutorial


Hai sobat, pada artikel sebelumnya yang berjudul Input with EditText in Messagebox Android Tutorial, saya telah menelaskan bagaimana cara memasukkan form atau EditText di Messagebox android dana menambahkan fungsi perhitungan di Messagebox. Dan kali ini saya akan menjelasakan kepada sobat cara membuata Spinner di anadroid. Apa itu spinner? berikut penjelasanya

Spinner Combolist in Android Tutorial

Spinner adalah objek yang hampir sama dengan ComboBox, tapi di android sebutanya adalah spinner. Spinner biasa digunakan untuk membuat objek yang menampung list yang dapat dipilih, dengan menyentuh objek spinner maka akan muncul menu dropdown yang menampilkan list. Untuk membuat objek spinner, berikut caranya :

Buat projek baru denga nama Spinner, sedangkan untuk package beri nama blogsetyaaji.com
Untuk activity_main.xml buat kode seperti berikut :


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

android_layout_width="match_parent"
android_layout_height="match_parent"
android_paddingBottom="@dimen/activity_vertical_margin"
android_paddingLeft="@dimen/activity_horizontal_margin"
android_paddingRight="@dimen/activity_horizontal_margin"
android_paddingTop="@dimen/activity_vertical_margin"
tools_context="com.blogsetyaaji.sinner.MainActivity">

<Spinner
android_id="@+id/spinner"
android_layout_width="250dp"
android_layout_height="wrap_content" />

<TextView
android_id="@+id/textView"
android_layout_width="match_parent"
android_layout_height="wrap_content" />
</RelativeLayout>

Pindah ke MainActivity.java, kodenya seperti berikut ini


package com.blogsetyaaji.sinner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity/* implements AdapterView.OnItemSelectedListener*/{

TextView teksPilih;
private Spinner sp_negara;
private String[] list = {"-Pilih-", "Amerika", "Indonesia", "Malaysia", "India"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

teksPilih = (TextView) findViewById(R.id.textView);

sp_negara = (Spinner) findViewById(R.id.spinner);
sp_negara.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
teksPilih.setText(list[position]);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
teksPilih.setText("");
}
});

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp_negara.setAdapter(adapter);

}
}

Jika sudah, jalankan aplikasi Spinernya dan hasilnya akan seperti berikut ini

Spinner Combolist in Android Tutorial

Spinner Combolist in Android Tutorial

Spinner Combolist in Android Tutorial


Mudah juga kan, konsepnya hampir sama seperti cara membuat Combobox pada program lain, dengan menyiapkan list dan memasukkanya ke dalam kode spinner, maka spinner akan muncul.
Sekian penjelasan saya tentang spinner di android semoga bermanfaat.


go to link download

Popular posts from this blog

Abbyy FineReader 14 Crack Plus Activation Key Free Download

Abbyy FineReader 14 Crack Plus Activation Key Free Download Legit and 100%working. Successfully tested Abbyy FineReader 14 Crack Plus Activation Key Free Download is here, download and enjoy. Safe and Secure. GET IT HERE! Abbyy FineReader 14 Crack Plus Activation Key Free Download --- Notes -- Thank You For Watching Our Video please visit our channel for more videos :) Download Link for the crack file is given below: Link: Abbyy FineReader 14 Crack Plus Activation Key Free Download How to install: - Download, extract and run .exe file, (If your antivirus blocking file, pause it or disable it for some time.) - Choose destination folder How to Use: Open destination folder and locate file notes.txt, open it and read step by step. Enjoy! Dont forget to read instructions after installation. Enjoy Abbyy FineReader 14 Crack Plus Activation Key Free Download. All files are uploaded by users like you, we cant guarantee that Abbyy FineReader 14 Crack Plus Activation Key Free Download are up to ...

Naval War Arctic Circle Compressed PC Game Free Download

Naval War Arctic Circle Compressed PC Game Free Download Naval War Arctic Circle Publisher: contradiction in terms Interactive Naval War Arctic Circle Developer: TURBO TAPE GAMES Naval War Arctic Circle Genre: Strategy Gamers use battleships, submarines, helicopters, and jets in fundamental quantity battles as they fight for management of the frigid northern seas in armed service War Arctic Circle. two full campaigns understand players commanding real-world units from Brits, German, U.S., and Russian militaries, among others, as they explore quite thirty 5 million sq. kilometers of ocean and lineation. Locating opponents is also a key challenge, therefore gamers ought to use measuring device, sonar, and AWACS-equipped craft to scout enemies before offensive. Multiplayer fans can also head on-line for competitive skirmishes. Naval War Arctic Circle Features: Unleash missiles, bombs, and torpedoes to blast foes inside the air, on land, and below the ocean Head on-line to want on friends ...

Windows 8 1 With Update AIO 24 In 1 Pre Activated Sep 2014

Windows 8 1 With Update AIO 24 In 1 Pre Activated Sep 2014 Ini merupakan update terbaru  Windows 8.1  yang sudah terintegrasi dengan  update-an  dari  microsoft  sampai dengan  10 Sep 2014 . Windows ini tidak ada yang di perbaharui atou di ubah dengan cara apapun, dan di dalam  Os  ini juga terdapat  versi 32-bit  dan  64-bit , jadi dapat di install  sesuai dengan  spesifikasi  PC sobat. Os ini berkapasitas  3.82Gb , jadi sobat harus menyediakan flashdisk sekitar  8  atau  16Gb , untuk dapat menjalankan Os ini !   Features :    �  NetFx 4.5.2   �  Windows 8.1 with Update MSDN/ESD download   �  USB Fat32 UEFI-bootable split-wim format.   �  DaRT 8.1 integrated into boot.wim and winre.wim recovery options.   �  UEFI bootdata in addition to BIOS bootdata   �  Diskpart/apply script with recovery image and multi-boot support v1.2...