我有一个微调器,它在自动选择时启动活动。我如何有一个提交按钮,以便用户可以首先选择他们想要启动的活动,然后点击提交以转到选定的屏幕?这是我目前拥有的:
private Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("TEST", "this is a test");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.entries,
android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new function());
}
public class function implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View arg1, int pos,
long id) {
String selection = ((TextView)arg1).getText().toString();
if (selection.equals("Red Screen")){
Intent intent = new Intent(arg1.getContext(), DisplayMessageActivity.class);
startActivity(intent);
}else if(selection.equals("Math Screen")){
Intent intent = new Intent(arg1.getContext(), Numbers.class);
startActivity(intent);
}else{
Intent intent = new Intent(arg1.getContext(), Face.class);
startActivity(intent);
}