Note that there are some explanatory texts on larger screens.

plurals
  1. POsaving a button's state
    primarykey
    data
    text
    <p>Anyone knows how to save a button's state? I want to enable a button which will be enabled permanently based on certain condition, it should remain enabled even the user exits the application. I already did the enabling of the button. Now how can I save it to make it enabled all through out? </p> <p>I am setting it enable this way. I am using putExtra on the other class to set a button enable.</p> <pre><code>Button page2 = (Button) findViewById(R.id.button2); Intent intent2=getIntent(); String isEnabled2 = intent2.getStringExtra("isEnabled2"); if(isEnabled2==null||isEnabled2.equals("disabled")){ page2.setEnabled(false); } else{ page2.setEnabled(true); } page2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), p3.class); startActivityForResult(myIntent, 0); } }); </code></pre> <p><strong>EDIT</strong></p> <pre><code>Button page2 = (Button) findViewById(R.id.button2); Intent intent2=getIntent(); String isEnabled2 = intent2.getStringExtra("isEnabled2"); if(isEnabled2==null||isEnabled2.equals("disabled")){ page2.setEnabled(false); } else { page2.setEnabled(true); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Enable.this); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("Name",true); //name is the key so may use a username or whatever you want editor.commit(); } SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean btnEnabled = preferences.getBoolean("Name",false); //false because you probably want that as your default value if(btnEnabled) { page2.setEnabled(true); } page2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), p3.class); startActivityForResult(myIntent, 0); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload