mercredi 9 septembre 2015

Java If Statements/Spinner

I'm working on an Activity where I need to start a new Activity at the click of a button based on the selected item in a spinner. I can't quite figure it out. This is what I have after clearing failed attempts.

spinner = (Spinner)findViewById(R.id.spinner);
adapter = ArrayAdapter.createFromResource(this, R.array.user_type, android.R.layout.simple_spinner_item);


adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                if(spinner.equals("My String Here")){

                    startActivity(new Intent(Register.this, *****.class));
                }else{
                startActivity(new Intent(Register.this, *****.class));


            }}

Am I better off just installing two buttons with their own proper syntax starting new activities separately?

Aucun commentaire:

Enregistrer un commentaire