Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Time Zone list in Android for pick/result

Tags:

android

I see that it's possible to launch the date & time settings via an intent in Android, but what I'd like to do is launch just the list that shows the time zones (clicking "Select time zone") and get back the selected value without having the selection modify the user's date & time settings. Any idea how to do this?

like image 817
tronman Avatar asked Dec 05 '22 01:12

tronman


1 Answers

If you are talking about a spinner you could do something like this:

ArrayAdapter <CharSequence> adapter =
          new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item );
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String[]TZ = TimeZone.getAvailableIDs();
    ArrayList<String> TZ1 = new ArrayList<String>();
    for(int i = 0; i < TZ.length; i++) {
        if(!(TZ1.contains(TimeZone.getTimeZone(TZ[i]).getDisplayName()))) {
            TZ1.add(TimeZone.getTimeZone(TZ[i]).getDisplayName());
        }
    }
    for(int i = 0; i < TZ1.size(); i++) {
        adapter.add(TZ1.get(i));
    }
    final Spinner TZone = (Spinner)findViewById(R.id.TimeZoneEntry);
    TZone.setAdapter(adapter);
    for(int i = 0; i < TZ1.size(); i++) {
        if(TZ1.get(i).equals(TimeZone.getDefault().getDisplayName())) {
            TZone.setSelection(i);
        }
    }

Take a look here for more literature on TimeZone

like image 78
CornCat Avatar answered Dec 21 '22 10:12

CornCat