IF condition on spinner

Put your problem here if it does not fit any of the other categories.

IF condition on spinner

Postby mazjoe » Mon Jul 02, 2012 5:20 am

i have problem about IF condition...i'm a beginer in android developer

i have this code
Code: Select all
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.ImageView;
import android.widget.Button;


public class spinner extends Activity implements
AdapterView.OnItemSelectedListener {
   
   String[] arrjenis = {"Gitar akustik", "gitar elektrik", "bass akustik", "bass elektrik"};
    String[] arrmerek = {"ibanez", "yamaha", "fender", "schecter"};
    Button Button01;

   @Override
   public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.main);
      
      Spinner spin = (Spinner) findViewById(R.id.Spinner01);
      spin.setOnItemSelectedListener(this);
      ArrayAdapter aa = new ArrayAdapter(
            this,
            android.R.layout.simple_spinner_item,
            arrjenis);

      aa.setDropDownViewResource(
         android.R.layout.simple_spinner_dropdown_item);
      spin.setAdapter(aa);
      
      
      Spinner spin1 = (Spinner) findViewById(R.id.Spinner02);
      spin1.setOnItemSelectedListener(this);
      ArrayAdapter bb = new ArrayAdapter(
            this,
            android.R.layout.simple_spinner_item,
            arrmerek);

      bb.setDropDownViewResource(
         android.R.layout.simple_spinner_dropdown_item);
      spin1.setAdapter(bb);
      
      ImageView imageView = (ImageView) findViewById(R.id.imageview1);
      Button01 = (Button)findViewById (R.id.Button01);
      Button01.setOnClickListener( new clicker());
      
   }

   public void onItemSelected(AdapterView<?> spin, View arg1, int posisi,
         long arg3) {
      // TODO Auto-generated method stub
      switch(spin.getId()){
         case R.id.Spinner01:
            String gitarSelected=arrjenis[posisi];
         break;
         case R.id.Spinner02:
            String merkSelected=arrmerek[posisi];
         break;
      }
   }
class  clicker implements  Button.OnClickListener
   {
public void onClick(View v) {
if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
          {
           imageView.setImageResource(R.drawable.xxxxxxxxxxxx);
          }
}


my question :
how to display images
- if spinner01 (arrjenis) is checked "Gitar akustik" and spinner02 (arrmerek) is checked "ibanez" then if button01 pressed, imageView drawing up an acoustic guitar brands ibanez (drawings had been prepared in folder drawable)

other condition

- if spinner01 (arrjenis) is checked "bass elektrik" and spinner02 (arrmerek) is checked "fender" then if button01 pressed, imageView drawing up an electrik bass brands fender (picture had been prepared in folder drawable)

etc..

sorry if my english bad 8)
mazjoe
Freshman
Freshman
 
Posts: 2
Joined: Mon Jul 02, 2012 5:06 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 22 guests