简体   繁体   中英

How to Enable buttons when an Item is clicked/selected using AutoCompleteTextView

There are 4 buttons which need to be disabled until an item resourced through an array is selected/clicked using

AutoCompleteTextView

I tried using the following code to perform this action. However, the buttons still remain enabled in all instances. Could someone correct me where I went wrong?

final Button btn1 = (Button) findViewById(R.id.home_new_sale);
final Button btn2 = (Button) findViewById(R.id.home_dues);
final Button btn3 = (Button) findViewById(R.id.home_returns);
final Button btn4 = (Button) findViewById(R.id.home_history);

//Initializing an OnItemClick Listener for AutoCompleteTextView
home_search.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        btn1.setEnabled(true);
        btn2.setEnabled(true);
        btn3.setEnabled(true);
        btn4.setEnabled(true);
    }

});

I've never used the AutoCompleteTextVierw, but it seems that your OnItemClickListener enables all buttons no matter which item is clicked.

I suggest you use a switch in the onItemClick() to make sure you enable only the correct button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM