我在 上添加了数组,这些字符串在我运行应用程序时string.xml
可见。Spinner
问题是Toast
不显示性别变量的值。
我为此制作了一个单独的课程,因为我还将Spinners
用于birthmoth、birthdate和birthyear。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
//SPINNERS
spinner_gender = (Spinner) findViewById(R.id.reg_gender);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.array_gender, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_gender.setAdapter(adapter);
spinner_gender.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener
{
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id)
{
genderString = parent.getItemAtPosition(pos).toString();
Toast.makeText(getBaseContext(), parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG);
}
public void onNothingSelected(AdapterView<?> parent)
{
// Do nothing.
}
}