gpt4 book ai didi

android - 在 fragment 中设置微调器

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:46 24 4
gpt4 key购买 nike

我正在尝试从我的 public final class Manual extends FragmentonCreateView 中的一个 fragment 中的字符串数组中设置微调器的值:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.manual, container, false);

String [] values =
{"Time at Residence","Under 6 months","6-12 months","1-2 years","2-4 years","4-8 years","8-15 years","Over 15 years",};
Spinner spinner = (Spinner) v.findViewById(R.id.spinner1);
ArrayAdapter<String> LTRadapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
LTRadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(LTRadapter);

return inflater.inflate(R.layout.manual, container, false);

}

我的代码没有错误,但是它没有设置微调器。微调器保持空白,没有任何值。关于为什么我的代码没有设置微调器的任何想法?

最佳答案

问题是我返回的是一个新 View ,而不是我设置的 View 。我必须 return v; 并且它工作正常。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.manual, container, false);

String [] values =
{"Time at Residence","Under 6 months","6-12 months","1-2 years","2-4 years","4-8 years","8-15 years","Over 15 years",};
Spinner spinner = (Spinner) v.findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adapter);

return v;

}

关于android - 在 fragment 中设置微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12238155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com