Professional Documents
Culture Documents
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation = "vertical"
tools:context="com.example.project_spinner.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pilih negara" />
<Spinner
android:id="@+id/negara"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tampil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pilih Buah" />
<Spinner
android:id="@+id/buah"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
3. Pada MainActivity.java
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
negara = (Spinner)findViewById(R.id.negara);
buah = (Spinner)findViewById(R.id.buah);
tampil = (TextView)findViewById(R.id.tampil);
ArrayAdapter<CharSequence>adapter =
ArrayAdapter.createFromResource(this, R.array.list_negara,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item
);
negara.setAdapter(adapter);
negara.setOnItemSelectedListener(new function());
//negara.setOnItemSelectedListener(new function());
ArrayAdapter<CharSequence>adapter2 =
ArrayAdapter.createFromResource(this, R.array.list_buah,
android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_ite
m);
buah.setAdapter(adapter2);
buah.setOnItemSelectedListener(new function2());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub