-1

In here 'AutoCompleteTextView' loads country list from 'Locale' with following code.

   public static ArrayList getCountryList()
        {
            Locale[] locale = Locale.getAvailableLocales();
            ArrayList<String>countries = new ArrayList<String>();
            String country = "";
            for( Locale loc : locale ){
                country = loc.getDisplayCountry();
                if( country.length() > 0 && !countries.contains(country) ){

                    countries.add( country );
                }
            }

            if(Build.VERSION.SDK_INT<=Build.VERSION_CODES.LOLLIPOP){
                countries.add("Sri Lanka");
            }
            Collections.sort(countries, String.CASE_INSENSITIVE_ORDER);

            return countries;

        }



@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    countryAutoTextView.setAdapter(new ArrayAdapter<String>(this, R.layout.country_list_spinner_loader, getCountryList()));

    changeLanguageButton.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
            Locale locale = new Locale(language);
            Resources res = getResources();
            DisplayMetrics dm = res.getDisplayMetrics();
            Configuration conf = res.getConfiguration();
            conf.locale = locale;
            res.updateConfiguration(conf, dm);
            finish();
            Intent refresh = new Intent(this, MainActivity.class);
            startActivity(refresh);
      }
   });   

}

country_list_spinner_loader.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/location_text_view"
    android:maxLines="5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:gravity="start"
    android:ellipsize="marquee"
    android:textColor="@color/colorBlack"
    android:textSize="14sp"/>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/first_Screen_greeting_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/greeting_layout_height"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#80000000"
        android:orientation="horizontal"
        android:paddingLeft="10dp"
        android:paddingRight="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_marginTop="2dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/ic_menu_search"
                android:layout_gravity="center"/>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="true">


                <AutoCompleteTextView
                    android:id="@+id/main_activity_country_auto"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/auto_text_height"
                    android:focusableInTouchMode="true"
                    android:textColor="@color/colorWhite"
                    android:textSize="@dimen/country_auto_text_size"
                    android:theme="@style/Autocomplete" />

            </android.support.design.widget.TextInputLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="@dimen/time_image_view_left_margin"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

For English language it's working fine for all the Android versions. But after changing the 'Locale' language specially "Sinhala" and "Hindi" as per user preference 'AutoCompleteTextView' is not loading countries for Android Nougat(24) in real devices and also emulators.

Finally I monitor that issue with android 'Log cat' when debug-gable device has Android Nougat. That is, When 'Locale' language is English, 'Log cat' displays following and 'Auto complete text view' loaded correctly.

07-03 15:20:01.116 17445-17445/com.sample D/AbsListView: Get MotionRecognitionManager
07-03 15:20:01.119 17445-17445/com.sample D/MotionRecognitionManager: mSContextService = com.samsung.android.hardware.context.ISemContextService$Stub$Proxy@5ba90df
07-03 15:20:01.121 17445-17445/com.sample D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@40dd12c
    motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@40dd12c
07-03 15:20:01.127 17445-17445/com.sample D/TextView: setTypeface with style : 0
07-03 15:20:01.137 17445-17445/com.sample D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: ThreadedRenderer.create() translucent=true
07-03 15:20:01.143 17445-17445/com.samplea D/InputTransport: Input channel constructed: fd=77
07-03 15:20:01.144 17445-17445/com.samplea D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: setView = android.widget.PopupWindow$PopupDecorView{51cd418 V.E...... ......I. 0,0-0,0} touchMode=true
07-03 15:20:01.147 17445-17445/com.sample D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: dispatchAttachedToWindow
07-03 15:20:01.177 17445-17445/com.sample D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,664][1440,820] result=0x27 surface={isValid=true 491593586176} surfaceGenerationChanged=true
    mHardwareRenderer.initialize() mSurface={isValid=true 491593586176} hwInitialized=true
07-03 15:20:01.180 17445-17575/com.sample D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000,  [1696x412]-format:1
07-03 15:20:01.181 17445-17445/com.sample D/AbsListView:  onsize change 
07-03 15:20:01.185 17445-17445/com.sample D/TextView: setTypeface with style : 0
07-03 15:20:01.207 17445-17445/com.sample D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: Relayout returned: oldFrame=[0,664][1440,820] newFrame=[0,664][1440,820] result=0x1 surface={isValid=true 491593586176} surfaceGenerationChanged=false
07-03 15:20:01.218 17445-17445/com.sample D/ViewRootImpl@ce15bfb[PopupWindow:333598a]: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1

But, when 'Locale' language is "Sinhala" or "Hindi", above 'Logcat' lines are not displaying and nothing loaded to the 'Auto complete text view'.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nuwan Withanage
  • 393
  • 7
  • 19

1 Answers1

0

For loading country list for 'AutoCompleteTextView'.

final ArrayAdapter<String>adapter = new ArrayAdapter<String>(this, R.layout.country_list_spinner_loader, DataLists.getCountryList());
        countryAutoTextView.setAdapter(adapter);

        adapter.registerDataSetObserver(new DataSetObserver() {
            @Override
            public void onChanged() {
                super.onChanged();
                Log.d("MAIN_COUNTRY_ADAPTER", "dataset changed");
                Object item = adapter.getItem(0);

                Log.d("MAIN_COUNTRY_ADAPTER", "item.toString "+ item.toString());
            }
        });

Instead of following method I used Hard coded countries for the list.

public static ArrayList getCountryList()
    {
        Locale[] locale = Locale.getAvailableLocales();
        ArrayList<String>countries = new ArrayList<String>();
        String country = "";
        for( Locale loc : locale ){
            country = loc.getDisplayCountry();
           if( country.length() > 0 && !countries.contains(country) ){

               countries.add( country );            
           }
        }

       if(Build.VERSION.SDK_INT<=Build.VERSION_CODES.LOLLIPOP){
            countries.add("Sri Lanka");
        }
       Collections.sort(countries, String.CASE_INSENSITIVE_ORDER);

       Log.d("DATA_LIST_CLASS", "COUNTRIES_LIST_SIZE_IS: " + countries.size() + countries.get(0) + countries.get(1));

        return countries;
    }

Because this also used 'Locale' to load the countries. It is an issue for changing device language and load the 'AutoCompleteTextView'.

Nuwan Withanage
  • 393
  • 7
  • 19