我创造了一个微调器。选择一个项目后,我想显示一个toast,它将显示所选内容。我怎么能这样做?
答案 0 :(得分:3)
试试这段代码。它对我来说很好用:
Spinner spinnerone = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapterone = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item,mtype2);
spinnerone.setAdapter(adapterone);
spinnerone.setSelection(0);
spinnerone.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
int item = spinnerone.getSelectedItemPosition();
y = mtype2[item];
Toast.makeText(getApplicationContext(), y, Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
答案 1 :(得分:1)
http://developer.android.com/reference/android/widget/Toast.html提供了有关Android Toast功能的所有信息。