Android的微调作用于旋转怪异

编程入门 行业动态 更新时间:2024-10-22 18:30:11
本文介绍了Android的微调作用于旋转怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有它不同的纱厂一个fragement。要让这些微调显示我正在使用自定义arrayAdapter(SpinnerHintAdapter)初始(非可选)值。这个类中唯一重要的事情是覆盖getCount将(),所以选择阵列的最后一个项目没有显示,这是初始值的存储位置。结果这一切工作正常,直到你旋转设备,那么微调设置就行了因为某些原因最后正常值,即使碎片类仍然认为它的设置初始值。结果任何人任何线索为什么发生这种情况和/或如何解决这个问题?

code样品:结果片段:

@覆盖公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){    查看rootView = inflater.inflate(R.layout.fragment_free_top_up,集装箱,FALSE);    微调宠=(微调)rootView.findViewById(R.id.pet);    SpinnerHintAdapter<&CharSequence的GT; petAdapter = SpinnerHintAdapter.createFromResource(getActivity(),        R.array.pet_array,android.R.layout.simple_spinner_item);    petAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    pet.setAdapter(petAdapter);    pet.setSelection(pet.getCount());    返回rootView;}

SpinnerHintAdapter:

@覆盖公众诠释的getCount(){    诠释计数= super.getCount();    //最后一个项目将是心领神会。    返回计数> 0?计数 - 1:计数;}

例如字符串数组

<字符串数组名=pet_array>    <项目>是< /项目>    <项目&GT否LT; /项目>    <项目>(初值)LT; /项目>< /字符串数组>

解决方案

还没有找到答案,这个具体问题,但用另一种方法来显示它可以在这里找到一个初始值:stackoverflow/a/12221309/3453217

任何澄清了什么毛病我第一次尝试仍然是受欢迎的。

I have a fragement with various Spinners in it. To have these spinners display an initial (non selectable) value I'm using a custom arrayAdapter (SpinnerHintAdapter). The only important thing this class does is override the getCount() so the last item of the selection-array isn't displayed, this is where the initial value is stored. This all works fine untill you rotate the device, then the spinners are set on the last normal value of the list for some reason, even though the Fragment class still thinks it's set on the initial value. Anyone any clue why this happens and / or how to solve this problem?

Code samples: fragment:

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_free_top_up, container, false); Spinner pet = (Spinner) rootView.findViewById(R.id.pet); SpinnerHintAdapter<CharSequence> petAdapter = SpinnerHintAdapter.createFromResource(getActivity(), R.array.pet_array, android.R.layout.simple_spinner_item); petAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); pet.setAdapter(petAdapter); pet.setSelection(pet.getCount()); return rootView; }

SpinnerHintAdapter:

@Override public int getCount() { int count = super.getCount(); // The last item will be the hint. return count > 0 ? count - 1 : count; }

example string-array

<string-array name="pet_array"> <item>Yes</item> <item>No</item> <item>(initial value)</item> </string-array>

解决方案

Haven't found an answer to this specific problem but used another method to display an initial value which can be found here: stackoverflow/a/12221309/3453217

Any clarification as to what went wrong with my first attempt is still welcome.

更多推荐

Android的微调作用于旋转怪异

本文发布于:2023-10-25 13:46:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527126.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:怪异   作用于   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!