简体   繁体   English

如何在Android应用程序上设置默认国家/地区代码

[英]How can i set a default country code on my Android application

I want to make a certain country code to becomes default but right now it comes in ascending order. 我想使某个国家/地区代码成为默认代码,但现在它以升序排列。

How can I achieve that? 我该如何实现?

Here is sample code: 这是示例代码:

 private void initViews() {

        registrationBean = new RegistrationBean();

        viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper_registration);
        viewFlipper.setDisplayedChild(0);

        llVerification = (LinearLayout) findViewById(R.id.ll_registration_mobile_otp);
        txtVerificationLabel = (TextView) findViewById(R.id.txt_registration_mobile_otp_label);

        spinnerCountryCodes = (Spinner) findViewById(R.id.spinner_registration_mobile_country_code);
        countryListBean = AppConstants.getCountryBean();
        Collections.sort(countryListBean.getCountries());
        List<String> countryDialCodes = new ArrayList<>();
        for (CountryBean bean : countryListBean.getCountries()) {
            countryDialCodes.add(bean.getDialCode());
        }

Add the default country code in the list at the 0th index after for loop like: 在循环之后,在列表的第0个索引处添加默认国家代码,例如:

for (CountryBean bean : countryListBean.getCountries()) {
    countryDialCodes.add(bean.getDialCode());
}
countryDialCodes.add(0, yourDefaultCountryCode);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android:如何在模拟器中手动设置国家/地区代码 - android : How to set Country code manually in emulator 如何从我的 Android 应用程序中的 Java 代码在我的布局上添加 NumberPicker? - How can I add NumberPicker on my Layout from Java code in my Android application? 如何为新工作区设置默认代码格式和模板 - How can I set the default code formatting and template for a new workspace 如何在Java中为页面设置默认边距 - How can I set default margins for my page in java 如何在Java的构造函数中设置默认的String格式? - How can I set a default String format in my constructor in Java? 如何设置默认项目以安装在Android Studio中? - How can I set the default project to install in Android Studio? 将应用程序设置为默认android - set application default android 如何在Android上获取用户的国家/地区代码? - How do I get the country code of a user on Android? Android Studio QR码扫描仪Zxing。 如何在我的应用程序中打开QR码扫描的结果(URL链接)? - Android Studio QR Code Scanner Zxing. How can I open the Result of the QR Code scan (URL Link) within my Application? 如何在android中获取国家代码(调用代码)? - How to get country code(calling code) in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM