title: How do I disable back button from the adapter to a fragment?
body: <p>Please don't mark this as duplicate because the past questions weren't able to solve my problem.</p>
  
  <p>I've already tried</p>
  
  <pre><code>@Override
  onBackPressed(){
  //do nothing
  }
  </code></pre>
  
  <p>but it wasn't able to solve my problem.</p>
  
  <p>My expectation for the output will be if the user pressed back, then he/she won't be able to do so since back pressed has been disabled and it should show a dialog box.</p>
  
  <p>This is what I came up with, It's from an adapter:</p>
  
  <pre><code>public void onBackPressed() {
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
              alertDialog.setTitle("Restart Progress");
              alertDialog.setMessage("Are you sure you want to restart all the progress?");
  
              alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                  Intent intent = new Intent(context, NavDrawer.class);
                      context.startActivity(intent);
                  }
              });
  
              alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.cancel();
  
                  }
              });
  
              AlertDialog alertDialog1 = alertDialog.create();
              alertDialog1.show();
  }
  </code></pre>
  
  <p>While in my activity class is this:</p>
  
  <pre><code>@Override
      public void onBackPressed() {
      weeklyExerciseAdapter2.onBackPressed();
          super.onBackPressed();
      }
  </code></pre>