Java 更改区域设置后AutoCompleteTextView不工作
在这里,“AutoCompleteTextView”使用以下代码从“Locale”加载国家/地区列表Java 更改区域设置后AutoCompleteTextView不工作,java,android,arraylist,locale,autocompletetextview,Java,Android,Arraylist,Locale,Autocompletetextview,在这里,“AutoCompleteTextView”使用以下代码从“Locale”加载国家/地区列表 public static ArrayList getCountryList() { Locale[] locale = Locale.getAvailableLocales(); ArrayList<String>countries = new ArrayList<String>();
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);
}
});
}
但是,当“Locale”语言为“Sinhala”或“Hindi”时,上面的“Logcat”行不会显示,也不会加载任何内容到“自动完成文本视图”。用于加载“自动完成文本视图”的国家/地区列表
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());
}
});
final ArrayAdapteradapter=新的ArrayAdapter(这个,R.layout.country_list_微调器_加载器,DataLists.getCountryList());
countryAutoTextView.setAdapter(适配器);
registerDataSetObserver(新的DataSetObserver(){
@凌驾
更改后的公共无效(){
super.onChanged();
Log.d(“主要国家/地区适配器”,“数据集已更改”);
对象项=适配器.getItem(0);
Log.d(“主适配器”,“item.toString”+item.toString());
}
});
我用硬编码的国家来代替下面的方法
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;
}
publicstaticarraylistgetcountrylist()
{
Locale[]Locale=Locale.getAvailableLocales();
ArrayListcountries=新的ArrayList();
字符串country=“”;
for(Locale loc:Locale){
country=loc.getDisplayCountry();
if(country.length()>0&&!countries.contains(country)){
国家。添加(国家);
}
}
如果(Build.VERSION.SDK)仅显示问题或本地数据未提交?是否签入调试器。@Harshal Deshmukh是的,这是一个显示问题,getCountryList不为null@countryAutoTextView.setAdapter(新ArrayAdapter(此,R.layout.country\u列表\微调器\加载器,getCountryList());而且此问题仅适用于“僧伽罗”语言。然后将xml文件代码添加到此处Country_list_spinner_loader和
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
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());
}
});
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;
}