title: Trying to insert contact into edittext using contact picker
body: <p>I'm trying to allows user to insert their number using a contact picker in android. I am currently using the example from post 2 in <a href="https://stackoverflow.com/questions/6155612/getting-number-from-contacts-picker">Getting Number from Contacts Picker</a> the contact picker appears and so but when i select a contact the contact number doesn't affect inside my edittext.
  There's no logcat error or whatsoever.</p>
  
  <p>My code:</p>
  
  <pre><code>public void doLaunchContactPicker(View view) {  
      Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,  
              Contacts.CONTENT_URI);  
      startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  
  }  
  
  @Override  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
      if (resultCode == RESULT_OK) {  
  
              switch (requestCode) {  
          case CONTACT_PICKER_RESULT:
              Cursor cursor = null;  
              String phoneNumber = "";
              List&lt;String&gt; allNumbers = new ArrayList&lt;String&gt;();
              int phoneIdx = 0;
              try {  
                  Uri result = data.getData();  
                  String id = result.getLastPathSegment();  
                  cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
                  phoneIdx = cursor.getColumnIndex(Phone.DATA);
                  if (cursor.moveToFirst()) {
                      while (cursor.isAfterLast() == false) {
                          phoneNumber = cursor.getString(phoneIdx);
                          allNumbers.add(phoneNumber);
                          cursor.moveToNext();
                      }
                  } else {
                      //no results actions
                  }  
              } catch (Exception e) {  
                 //error actions
              } finally {  
                  if (cursor != null) {  
                      cursor.close();
                  }
                  final EditText phoneInput = (EditText) findViewById(R.id.mobileno);
  
                  final CharSequence[] items = allNumbers.toArray(new String[allNumbers.size()]);
                  AlertDialog.Builder builder = new AlertDialog.Builder(SIMMessageSenderActivity.this);
                  builder.setTitle("Choose a number");
                  builder.setItems(items, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int item) {
                          String selectedNumber = items[item].toString();
                          selectedNumber = selectedNumber.replace("-", "");
                          phoneInput.setText(selectedNumber);
                      }
                  });
                  AlertDialog alert = builder.create();
                  if(allNumbers.size() &gt; 1) {
                      alert.show();
                  } else {
                      String selectedNumber = phoneNumber.toString();
                      selectedNumber = selectedNumber.replace("-", "");
  
                      phoneInput.setText(selectedNumber);
                  }
  
                  if (phoneNumber.length() == 0) {  
                      //no numbers found actions  
                  }  
              }  
              break;  
          }  
      } else {
         //activity result error actions
      }  
  }
  </code></pre>