大佬教程收集整理的这篇文章主要介绍了android – 如何设置当前微调文本而不更改关联的选择列表项,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
| Monday | | Thuesday | | Wednesday | | Thursday | | Friday | | Saturday | | USER DEFINED |
当用户选择USER DEFINED时,他可以在对话框中输入自定义值,假设我将该值设为String userDef =“Your choice”.
我需要将此String设置为当前项,而不更改微调选择列表,必须与上述相同,当用户再次点击微调器时,如Google Analytics(分析)Android应用程序中的内容,请参阅该图像.
未点击的微调
点击微调
我该怎么做?
SpinnerAdapter
界面有两种不同但相关的方法:
> getView()
– 创建Spinner本身显示的视图.
> getDropDownView()
– 创建下拉弹出窗口中显示的视图.
因此,要使一个在弹出窗口本身不同弹出窗口中显示的项目,您只需要以不同的方式实现这两种方法.根据您的代码的细节,细节可能会有所不同,但一个简单的例子就是:
public class AdapterWithCustomItem extends ArrayAdapter<String> { private final static int position_user_DEFINED = 6; private final static String[] OPTIONS = new String[] { "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Custom..." }; private String mCustomText = ""; public AdapterWithCustomItem(Context context){ super(context,android.R.layout.simple_spinner_dropdown_item,OPTIONS); } @Override public View getView(int position,View convertView,ViewGroup parent) { View view = super.getView(position,convertView,parent); if (position == POSITION_user_DEFINED) { TextView tv = (TextView)view.findViewById(android.R.id.text1); tv.setText(mCustomText); } return view; } public void setCustomText(String customText) { // Call to set the text that must be shown in the spinner for the custom option. mCustomText = customText; notifyDataSetChanged(); } @Override public View getDropDownView(int position,ViewGroup parent) { // No need for this override,actually. It's just to clarify the difference. return super.getDropDownView(position,parent); } }
然后,当用户输入自定义值时,您只需要使用要显示的文本调用适配器上的setCustomText()方法即可.
@H_912_2@mAdapter.setCustomText("This is displayed for the custom option");产生以下结果:
以上是大佬教程为你收集整理的android – 如何设置当前微调文本而不更改关联的选择列表项全部内容,希望文章能够帮你解决android – 如何设置当前微调文本而不更改关联的选择列表项所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。