title: Android Increment counter value on button onClick
body: <p>I want to save a list in my database as List1, List2,-----, List(n+1). It is saving my list, but everytime I save a list it starts from List1. I want to save my list by picking the last saved List and increment it by 1. How to perform this?</p>
  
  <p>code:</p>
  
  <pre><code>btn_save_list.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {
                  ++counter;
                  showSavelistDialog(counter);
  
          }
      });
  private void showSavelistDialog(int counter) {
  if (!list.isEmpty()) {
  
          String draftName=  "Draft"+counter;
          SaleDraftDatabase saleDraftDatabase = new SaleDraftDatabase(
                  mActivity);
          saleDraftDatabase.open();
  
          boolean nameAvailable = saleDraftDatabase
                  .checkDraftNameAvailable(userId,draftName);
          if (nameAvailable) {
              boolean saveCheck = saleDraftDatabase.createEntry(list,
                      userId,draftName);
              saleDraftDatabase.close();
              if (saveCheck) {
                  SalesReturnDatabase saleDatabase = new SalesReturnDatabase(
                          mActivity);
                  saleDatabase.open();
                  saleDatabase.deleteAllEntriesOfSingleUser(userId);
                  saleDatabase.close();
                  list.clear();
                  barcodeList.clear();
                  Intent i = new Intent(mActivity,
                          Activity_Sales_Return.class);
                  i.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                          | Intent.FLAG_ACTIVITY_NEW_TASK);
                  startActivity(i);
                  finish();
                  Toast.makeText(
                          Activity_Sales_Return.this,
                          draftName
                                  + " sale saved as draft.",
                          Toast.LENGTH_SHORT).show();
              } else
                  Toast.makeText(Activity_Sales_Return.this,
                          "Some error occured", Toast.LENGTH_SHORT)
                          .show();
          } else {
  
              Toast.makeText(mActivity,
                      "Name already in use. Choose another name.",
                      Toast.LENGTH_SHORT).show();
          }
      }
  </code></pre>