正好用到了,怕忘记,记录下:
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
long time1 = System.currentTimeMillis();
ArrayList<String> citylList = TimezoneUtil
.getCitiesOfTimezone(position - 12);
String[] cities = new String[citylList.size()];
cities = (String[]) citylList.toArray(cities);
final String[] cityStrings = cities;
new AlertDialog.Builder(WorldClockSettingActivity.this)
.setTitle("Choose a city")
.setItems(cities, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
mCityTextView.setText(cityStrings[which]);
TimeZone timeZone = TimeZone.getTimeZone(cityStrings[which]);
// String name = timeZone.getDisplayName();
java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(WorldClockSettingActivity.this);
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(WorldClockSettingActivity.this);
timeFormat.setTimeZone(timeZone);
dateFormat.setTimeZone(timeZone);
String timeString = timeFormat.format(new Date());
String dateString = dateFormat.format(new Date());
mTimeTextView.setText(timeString);
mDaTextView.setText(dateString);
dialog.dismiss();
}
}).show();