我尝试使用微调器控件结果将其指向应用程序上的另一个屏幕。例如,在微调器控件中,如果用户选择 chevy,它将带您进入另一个屏幕,该屏幕在 chevy.xml 和 Chevy.class 中编码。这就是我目前所拥有的并且需要一些帮助,因为我们的书只使用了 getSelectedItem 并且该示例仅用于输出语句。
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
}
}