在微调器项目中选择特定项目后

在微调器项目中选择特定项目后

本文介绍了在微调器项目中选择特定项目后,Edittext希望从禁用中启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一页中使用Spinner,EditText和Button.Spinner包含以下项目...

I'm using Spinner,EditText and Button in one page.The spinner has these items ...

以下情况:

 String[] Items = {
            "Alarm",
            "Office",
            "Meeting",
            "Party",
            "Lunch",
            "Breakfast",
            "Supper",
            "Home",
            "Private",
            "Outdoor",
            "Family",
            "Friends",
            "others"
    };

    Spinner s1;

在其中,如果我在微调器项目中选择其他",则意味着仅必须启用Edittext,否则必须将其禁用.如果我选​​择其他某些项目,则必须禁用Edittext

In it if I select the "others" in spinner items means only the Edittext has to be enable otherwise it has to be disabled.If I select some other item Edittext has to be disabled

代码段:

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

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item, Items);

    s1.setAdapter(adapter);
    s1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        public void onItemSelected(AdapterView<?> arg0,
        View arg1, int arg2, long arg3)
        {
            int index = s1.getSelectedItemPosition();
            Toast.makeText(getBaseContext(),
                "You have selected item : " + Items[index],
                Toast.LENGTH_SHORT).show();
        }

        public void onNothingSelected(AdapterView<?> arg0) {}
    });

谢谢

推荐答案

执行此操作

    EditText edit = (EditText) findViewById(R.id.EditText01);
    edit.setEnabled(false);
    edit.setInputType(InputType.TYPE_NULL);
    edit.setFocusable(false);

和当选择任何其他选项为此,

And when any other option selected do this,

    edit.setEnabled(true);
    edit.setInputType(InputType.TYPE_CLASS_TEXT);
    edit.setFocusable(true);

这篇关于在微调器项目中选择特定项目后,Edittext希望从禁用中启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:34