安卓:微调提示 [英] Android: Spinner hint

查看:434
本文介绍了安卓:微调提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正是有作出提示类似暗示了对于编辑文本字段飞旋。我知道你可以使用一个提示,给你一个标题栏,但仍保留着最初的微调领域的空白,直到你点击进入微调。目前,我有设置一个空场的涡轮组合这是问题的第一部分的粗暴的方式,然后有一个检查结束时,以确保微调不等于问题的字符串。是否有这样做的任何清洁剂/更好的办法?

Is there anyway of making a hint for a spinner similar to hint that is provided for edit text fields. I know you can use a prompt that gives you a title bar but still leaves the initial spinner field blank until you click into the spinner. I currently have a crude way of setting a dummy field as the first part of the spinner array which is the question and then have a check at the end to make sure the spinner doesn't equal the question string. Is there any cleaner / better way of doing this?

谢谢!

推荐答案

下面是一个解决方案,这可能是比拉维维亚斯code有点简单(感谢灵感!):

Here's a solution which is probably a bit simpler than Ravi Vyas code (thanks for the inspiration!):

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item) {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v = super.getView(position, convertView, parent);
        if (position == getCount()) {
            ((TextView)v.findViewById(android.R.id.text1)).setText("");
            ((TextView)v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
        }

        return v;
    }       

    @Override
    public int getCount() {
        return super.getCount()-1; // you dont display last item. It is used as hint.
    }

};

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.add("Item 1");
adapter.add("Item 2");
adapter.add("Hint to be displayed");

spinner.setAdapter(adapter);
spinner.setSelection(adapter.getCount()); //display hint

这篇关于安卓:微调提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆