这是我的代码:
String[] spinnerPresets = { "Test", "Test1", "Test2" };
final Spinner s1 = new Spinner(this);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, spinnerPresets);
s1.setAdapter(arrayAdapter);
s1.setPrompt("Presets");
s1.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
if(position==0) {
Toast.makeText(Activity.this, "TEST", Toast.LENGTH_LONG).show();
}
if(position==1) {
Toast.makeText(Activity.this, "TEST1", Toast.LENGTH_LONG).show();
}
if(position==2) {
Toast.makeText(Activity.this, "TEST2", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
b2.setOnClickListener(new OnClickListener() {
public void onClick(View paramView) {
s1.performClick();
}
});
当我点击按钮时,它会显示我的微调器,但问题是,当我在该微调器中选择其中一些项目时,它不会显示Toast消息。
答案 0 :(得分:0)
我没试过,但你可以看看吗。
s1.setOnTouchListener(new OnTouchListener() {
int positon;
public boolean onTouch(View v, MotionEvent event) {
positon = s1.getSelectedItemPosition();
if(position==0) {
Toast.makeText(Activity.this, "TEST", Toast.LENGTH_LONG).show();
}
if(position==1) {
Toast.makeText(Activity.this, "TEST1", Toast.LENGTH_LONG).show();
}
if(position==2) {
Toast.makeText(Activity.this, "TEST2", Toast.LENGTH_LONG).show();
}
}
}
});