How to select different asset files as a language change using Locale and Configuration?

I want to change the JSON file from the resources folder according to the language change in my application and want to feel the data in RecyclerView.

But my adapter does not apply these changes.

+4
source share
2 answers

Make sure you need to install the adapter again after selecting another locale file. If you are using RecyclerView, then install the LayoutManager in your recycler view as follows:

RecyclerView yourRecyclerView= (RecyclerView) findViewById(R.id.yourRecyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
rc_qList.setHasFixedSize(true);
rc_qList.setLayoutManager(layoutManager);

RecyclerViewAdapter yourAdapter = new RecyclerViewAdapter (MainActivity.this, yourArrayList);
rc_qList.setAdapter(yourAdapter);
+4
source

Locale, Locale . :

Log.d(TAG, "onCreate: "+Locale.ENGLISH);
Log.d(TAG, "onCreate: "+Locale.getDefault().getDisplayLanguage());
Log.d(TAG, "onCreate: "+Locale.getDefault().getDisplayCountry());
Log.d(TAG, "onCreate: "+Locale.getDefault().getCountry());
Log.d(TAG, "onCreate: "+Locale.getDefault().getLanguage());

:

onCreate: en
onCreate: English
onCreate: United Kingdom
onCreate: GB
onCreate: en

adapter.notifyDataSetChanged() , , .

0

Source: https://habr.com/ru/post/1665587/


All Articles