Android Launch timezone list for selection / result

I see that it is possible to run the date and time settings with the intention in Android, but what I would like to do is run only the list that shows the time zones (click "Select time zone") and return the selected value without selecting, change the settings date and time of the user. Any idea how to do this?

+4
source share
4 answers

If you are talking about spinner, you can 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); } } 

Look here for more TimeZone literature.

+10
source

Inspired by the CornCats example above, a slightly different and shorter implementation with adapters that worked for me:

 private void populateAndUpdateTimeZone() { //populate spinner with all timezones mSpinner = (Spinner) findViewById(R.id.mytimezonespinner); String[] idArray = TimeZone.getAvailableIDs(); idAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, idArray); idAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(idAdapter); // now set the spinner to default timezone from the time zone settings for(int i = 0; i < idAdapter.getCount(); i++) { if(idAdapter.getItem(i).equals(TimeZone.getDefault().getID())) { mSpinner.setSelection(i); } } 
+3
source

I know this is old, but I'm also interested ...

I looked at it, and I do not think it is possible. I would love to do the same. This led either to the transfer of some of the Android GPL code to my application (ack), finding the configured database and code (JAR or java), or, finally, writing this code itself (double ack). Time intervals are a mine, and I hope not to write the code myself. There are many exceptions based on the location of users.

0
source

The Android system classes ZoneList.java and ZonePicker.java are used when creating the TimeZones list in the Date and Time settings. Link to the source of ZoneList.java

0
source

All Articles