Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edittext want to go enable from disable after select the particular item in the spinner items

Tags:

android

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

Following:

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

    Spinner s1;

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

Code snippet:

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) {}
    });

Thank you,

like image 402
ezhil Avatar asked Dec 06 '22 23:12

ezhil


1 Answers

Do this,

    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);
like image 182
Debarati Avatar answered May 13 '23 18:05

Debarati