0

I am getting problem with custom dialog, i created custom dialog and it works properly but im having confusion about not showing it again if user click on button. Like there is a button named rating when ever user click on that button then custom dialog will never open again. So if anyone knows how to do it then please help me

This is my code

   final Dialog dialogrul = new Dialog(MainActivity.this);
    dialogrul.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    Window window = dialogrul.getWindow();
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    dialogrul.setContentView(R.layout.exitlayout);
    Button rating = dialogrul.findViewById(R.id.ratingok);
    Button dialogok = dialogrul.findViewById(R.id.exityes);
    final Button dialognotok = dialogrul.findViewById(R.id.exitno);

    dialogrul.setCancelable(true);
    dialogrul.show();
    dialogok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MainActivity.this.onSuperBackPressed();
            finish();

        }
    });
    rating.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent j = new Intent(android.content.Intent.ACTION_VIEW);
            j.setData(Uri.parse("https://play.google.com/store/apps/details?"));
            startActivity(j);
        }
    });
    dialognotok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialogrul.cancel();

        }
    });

}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

You would probably have to write to a file to store a variable wich says if he clicked on the button

This is to read the file:

private String readFromFile(Context context) {

        String ret = "";

        try {
            InputStream inputStream = context.openFileInput("yourfilename.txt");

            if ( inputStream != null ) {
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String receiveString = "";
                StringBuilder stringBuilder = new StringBuilder();

                while ( (receiveString = bufferedReader.readLine()) != null ) {
                    stringBuilder.append(receiveString);
                }

                inputStream.close();
                ret = stringBuilder.toString();
            }
        }
        catch (FileNotFoundException e) { } catch (IOException e) { }

        return ret;
    }

and this is to write to the file:

private void writeToFile(String data,Context context) {
        String x=readFromFile(this);
        try {
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("yourfilename.txt", Context.MODE_PRIVATE));
            outputStreamWriter.write(data);
            outputStreamWriter.close();
        }
        catch (IOException e) { }
    }