title: Android set selected item in alert dialog
body: <p>I'm creating an Alert Dialog in the beginning of my application to let the user to choose where to store the data which my application is downloading from web. The thing that I want to achieve now is depending on the size of Internal / External Storage I want to set selected one of the items. Here is the code which I'm using to create the dialog :</p>
  
  <pre><code>@SuppressWarnings("static-access")
  public void createDialog(){
  
  
      final CharSequence[] items = {"Phone Memory - "+memorysize+" free space", "SD Card - "+megAvailable+" MB free space"};
  
      final int userId = rpc.getUserId(this);
      final String servername = rpc.getCurrentServerName(this);
  
      SharedPreferences stampiiSettings = PreferenceManager.getDefaultSharedPreferences(MyCollectionList.this);
      final SharedPreferences.Editor editor = stampiiSettings.edit();
  
      AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent());
      builder.setTitle("Select Storage Path");
      builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
  
              if(item == 0){
  
                  rpc.createFoldersInInternalStorage(servername, userId, MyCollectionList.this);
                  Toast.makeText(getApplicationContext(), "Selected Storage Path : Phone Memory", Toast.LENGTH_SHORT).show();
                  editor.putInt("storagePath", 1);
                  editor.commit();
              } else if (item == 1){
  
                  rpc.createFoldersInExternalStorage(servername, userId, MyCollectionList.this);
                  Toast.makeText(getApplicationContext(), "Selected Storage Path : SD Card", Toast.LENGTH_SHORT).show();
                  editor.putInt("storagePath", 2);
                  editor.commit();
              }
          }});
  
          builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
                  mHandlerUpdateUi.post(mUpdateUpdateUi); // update UI            
          }
          });
          AlertDialog alert = builder.show();
  }
  </code></pre>
  
  <p>And another thing that I want to achieve, how can I prevent user to close the Alert Dialog if he didn't choose any item. I don't want to close the dialog on pressing back button or when he click OK button. Any ideas/ suggestions/ help are welcomed!</p>