Created
June 19, 2017 14:22
Spinner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.belajar.spinner; | |
import android.app.*; | |
import android.os.*; | |
import android.widget.*; | |
import android.view.View.*; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity | |
{ | |
Spinner Sp; | |
ImageView img; | |
private String [] Data ={ | |
"Pict 1","Pict 2","Pict 3","Pict 4","Pict 5", | |
}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Sp =(Spinner)findViewById(R.id.spinner); | |
img =(ImageView)findViewById(R.id.image); | |
; | |
ArrayAdapter<String> adp =new | |
ArrayAdapter<>(this,android.R.layout. | |
simple_list_item_checked, Data); | |
Sp.setAdapter(adp); | |
Sp.setOnItemSelectedListener(new | |
AdapterView.OnItemSelectedListener() | |
{ | |
@Override | |
public void onItemSelected(AdapterView<?> adapterView, View view, int Posisi, long l) | |
{ | |
// TODO: Implement this method | |
if(Posisi == 0) | |
{ | |
img.setBackgroundResource(R.drawable.cloud); | |
} | |
if(Posisi == 1) | |
{ | |
img.setBackgroundResource(R.drawable.compose); | |
} | |
if(Posisi == 2) | |
{ | |
img.setBackgroundResource(R.drawable.notebook); | |
} | |
if(Posisi == 3) | |
{ | |
img.setBackgroundResource(R.drawable.photos); | |
} | |
if(Posisi == 4) | |
{ | |
img.setBackgroundResource(R.drawable.repeat); | |
} | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> adapterView) | |
{ | |
// TODO: Implement this method | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment