我有这样一种添加项目的方法:
timezoneEdit.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
timezonSpin = (Spinner) findViewById(R.id.timezoneSpin);//timezoneCall();
final ArrayList <String> timezonelist = new ArrayList<String>();
timezonelist.add("Gvatemala");
timezonelist.add("Gonduras");
timezonelist.add("Batumi");
timezonelist.add("Boston");
timezonelist.add("Zhytomir");
timezonelist.add("Zmerinka");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(NewOrderActivity.this,
android.R.layout.simple_spinner_item, timezonelist);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timezonSpin.setAdapter(dataAdapter);timezonSpin.performClick();
timezonSpin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
Log.i("sd","Ya tut");
Log.i("choosed",timezonelist.get(position).toString());
timezoneEdit.setText(timezonelist.get(position));
}
public void onNothingSelected(AdapterView<?> arg0) {
TimeZone timezone = TimeZone.getDefault();
String TimeZoneName = timezone.getDisplayName();
int TimeZoneOffset = timezone.getRawOffset()/(60 * 60 * 1000);
Log.i("timezone",Integer.toString(TimeZoneOffset));
timezoneEdit.setText("UTC"+Integer.toString(TimeZoneOffset), TextView.BufferType.EDITABLE);
}
});
当用户单击按钮时,将显示微调器,用户可以选择其中一项。但奇怪的是 onItemSelectedListener 没有调用。我将这种shema用于我的其他常规微调器(无需单击按钮),并且那里一切正常……缺少什么?