Search code examples
androidbuttonandroid-activityonclicklistener

Android onClickListener action do not show this message again


This is the view

Here is the code

public class PraiseColleagueHelpScreenActivity extends AppCompatActivity
private Object view;

TextView okButton ;
TextView dontButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_praise_colleague_help_screen);
    okButton = (TextView) findViewById(R.id.ok_button);
    dontButton = (TextView) findViewById(R.id.dont_show_message_again);
    final Intent i = new Intent(this, PraiseColleaguePickerActivity.class);

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(i);

        }
    });

    dontButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(i);
        }
    });
}

When I click on the OK button it opens a db with a list of colleagues

My question is what to insert in the `

dontButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(i);
            }
        });`

so when I click on the Don't show this message again, it still opens the db with colleagues but I do not see the view on the next load.


Solution

  • You need to use sharePreferences or SQLite to save user's settings.

    For example , if the user does not want to be shown the message again , you can store the value in shared preferences and the next time he clicks, you can check the shared preferences and show or not show based on the value.