简体   繁体   English

重新创建片段后,微调器文本变为空白/白色

[英]Spinner Text Becomes Blank/White after Recreating Fragment

Why does the spinner text become blank after making a selection? 为什么选择后微调器文本变为空白?

The spinner text flashes and then becomes blank if I use getActivity().recreate(); 如果我使用getActivity(),则微调器文本闪烁然后变为空白.recreate(); after making a selection. 做出选择后。

I'm using recreate to load a locale based on the spinner selection. 我正在使用recreate来加载基于微调器选择的语言环境。

onCreateView

spinner = (Spinner) findViewById(R.id.spinner);

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {

((TextView) spinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.red));

getActivity().recreate();

switch (position) {

                case 0:
                    setLocale("en");
                    break;
                case 1:
                    setLocale("en-us");
                    break;
}
}

 @Override
                                              public void 
onNothingSelected(AdapterView<?> parent) {


                                              }
});

In an Activity, I would use getIntent and startactivity and the spinner text doesn't become blank. 在Activity中,我将使用getIntent和startactivity,并且微调器文本不会变为空白。

你可以尝试在你的片段的oncreate方法上放置setRetainInstance(true)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM