Android getSelectedItem, how to use?
Posted
by
user1881184
on Stack Overflow
See other posts from Stack Overflow
or by user1881184
Published on 2012-12-06T04:41:21Z
Indexed on
2012/12/06
5:03 UTC
Read the original article
Hit count: 120
Im trying use the spinner control result in order to point it to another screen that would be on the app. For example in the spinner control if the user chose chevy it would then take you to another screen which is coded in chevy.xml and Chevy.class. This is what i have thus far and need some help, as our book only used getSelectedItem and the example was only for an output statement. Please help.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
public class Mainpage extends Activity implements OnItemSelectedListener {
String carChoice, chevy, ford, dodge, toyota;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* carChoice = group.getSelectedItem().toString();
}
if (carChoice.compareTo(chevy)==0)
{
startActivity(new Intent(Mainpage.this, Chevy.class));
*/ }
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3)
{
final Spinner group = (Spinner) findViewById(R.id.carGroup);
group.setOnItemSelectedListener(this);
// TODO Auto-generated method stub
String selected = group.getItemAtPosition(1).toString();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
© Stack Overflow or respective owner