1-) Android - SPİNNER=COMBOBOX KULLANIMI
1-) ilk önce string.xml in içine aşşağıdakini yapıştır
<array name="renkler">
<item>Lütfen İtemi Seçiniz</item>
<item >mavi</item>
<item >turuncu</item>
<item >yeşil</item>
<item >kırmızı</item>
<item >sarı</item>
</array>
2-)sonra sol taraftaki layout klasorune sağtıkla en usttekıne tıkla spinner_gorunum.xml adında TextView oluştur.
Not=oluştururken Linearlayout yerine TextViev'i seç ve Aşşağıdaki kodları yapıştır.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/ripple_material_dark"
android:textColor="@color/abc_input_method_navigation_guard"
android:padding="5dp"
></TextView>
3-)sonra OnCreate metodunun bulunduğu yere aşşağıdakini yapıştır
Spinner sp= (Spinner) findViewById(R.id.spinner);//id=spinner
String[] renkler = getResources().getStringArray(R.array.renkler);//string.xml'den array dizisini alır
ArrayAdapter<String> adapter= new ArrayAdapter<>(getApplicationContext(), R.layout.spinner_gorunum , renkler);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext()," Seçilen renk "+renkler[position],Toast.LENGTH_SHORT).show();
switch (position) {
case 0: break;
case 1: zemin.setBackgroundColor(Color.YELLOW);break;
case 2: zemin.setBackgroundColor(Color.GREEN); break;
case 3: zemin.setBackgroundColor(Color.RED); break;
case 4: zemin.setBackgroundColor(Color.BLUE); break;
case 5: zemin.setBackgroundColor(Color.WHITE); break; } }