0

I want to disable button permanently after click on it. I am trying several time, but when I close the app or go back to the previous layout it remain enable.

btn1.setOnClickListener(new View.OnClickListener() {
        public void onClick (View v) {

            Integer t = count * 650;
            String tot = t.toString();
            selectseat.setText(selectseat.getText().toString() + " A1 ");
            fair.setText("Fair: " + tot);
            btn1.setBackgroundColor(Color.GREEN);
            btn1.setEnabled(false);

              /* if(flag == 1)
                 {
                   btn1.setBackgroundColor(Color.GREEN);
                    btn1.setEnabled(false);
                   Log.d("ins", "called");
                 }
               flag = 0;*/

            count++;
kamran
  • 5
  • 3

2 Answers2

2

There is no means for you to "permanently" disable a widget. You can disable a particular instance of a widget, using setEnabled(false), as you have in your question. You will simply need to track yourself that this widget is "permanently" disabled (e.g., save that data in SharedPreferences), then use setEnabled() to disable it on future runs of your app.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

You need to save your activity state in order to disable the button when you return back to that activity.

Try: Saving Android Activity state using Save Instance State

Community
  • 1
  • 1