【问题标题】:how to use libcore icu code in third party apps如何在第三方应用程序中使用 libcore icu 代码
【发布时间】:2019-08-02 14:34:09
【问题描述】:

我正在开发一个应用程序,我需要在其中获取与 Android AOSP 设置应用程序代码中 Zonepicker 类使用的时区列表相同的时区列表

https://android.googlesource.com/platform/packages/apps/Settings/+/android-4.3.1_r1/src/com/android/settings/ZonePicker.java

zonepicker 使用 SettingsLib,它在内部使用 android libcore,我尝试使用 libcore 库但无法在我的 Android Studio 项目中导入

谁能告诉我如何使用这个 libcore 库:libcore.util

【问题讨论】:

  • 您需要获取可用时区 rt 的列表吗?
  • 是的,但与设置应用程序显示的方式相同,按地区显示时区

标签: android datetime timezone


【解决方案1】:

您可以使用TimeZone.getAvailableIDs() 获取设备上所有可用时区的列表。

你可以试试下面的代码:-

public static SimpleAdapter constructTimezoneAdapter(Context context,
            boolean sortedByName, int layoutId) {
        final String[] from = new String[] {ZoneGetter.KEY_DISPLAYNAME, ZoneGetter.KEY_GMT};
        final int[] to = new int[] {android.R.id.text1, android.R.id.text2};

        final String sortKey = (sortedByName ? ZoneGetter.KEY_DISPLAYNAME : ZoneGetter.KEY_OFFSET);
        final MyComparator comparator = new MyComparator(sortKey);
        final List<Map<String, Object>> sortedList = ZoneGetter.getZonesList(context);
        Collections.sort(sortedList, comparator);
        final SimpleAdapter adapter = new SimpleAdapter(context,
                sortedList,
                layoutId,
                from,
                to);

        return adapter;
    }

【讨论】:

  • 我使用了相同的代码,但无法导入 Zonegetter 类,知道如何使用这个类
猜你喜欢
  • 2011-02-12
  • 1970-01-01
  • 2012-04-05
  • 1970-01-01
  • 2019-01-28
  • 2020-10-07
  • 2011-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多