title: Android convert EditText to String
body: <p>I know how to convert the EditText to a string, no clue why it doesn't work.</p>
  
  <pre><code>String username = user.getText().toString();
  
  user = (EditText)findViewById(R.id.username);
  </code></pre>
  
  <p>I am getting this error: "Method getText must be called from the UI thread, currently inferred thread is worker"</p>
  
  <p>Full code: </p>
  
  <pre><code>public class Login extends Activity implements OnClickListener{
  private EditText user;
  private Button bLogin;
  // Progress Dialog
  private ProgressDialog pDialog;
  // JSON parser class
  JSONParser jsonParser = new JSONParser();
  private static final String LOGIN_URL = "http://testapp.comlu.com/login.php";
  private static final String TAG_SUCCESS = "success";
  private static final String TAG_MESSAGE = "message";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
      user = (EditText)findViewById(R.id.username);
      String aID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
      bLogin = (Button)findViewById(R.id.login);
      bLogin.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
      switch (v.getId()) {
          case R.id.login:
              new AttemptLogin().execute();
              // here we have used, switch case, because on login activity you may //also want to show registration button, so if the user is new ! we can go the //registration activity , other than this we could also do this without switch //case.
          default:
              break;
      }
  }
  
  class AttemptLogin extends AsyncTask&lt;String, String, String&gt; {
      /**
       * Before starting background thread Show Progress Dialog
       * */
      boolean failure = false;
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(Login.this);
          pDialog.setMessage("Attempting for login...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }
  
      @Override
      protected String doInBackground(String... args) {
          // TODO Auto-generated method stub
          // here Check for success tag
          int success;
          String username = user.getText().toString();
          String androidID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
          try {
  
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("username", username));
              params.add(new BasicNameValuePair("androidID", androidID));
  
              Log.d("request!", "starting");
  
              JSONObject json = jsonParser.makeHttpRequest(
                      LOGIN_URL, "POST", params);
  
              // checking  log for json response
            Log.d("Login attempt", json.toString());
  
              // success tag for json
              success = 1;
              if (success == 1) {
                  Log.d("Successfully Login!", json.toString());
  
                  Intent ii = new Intent(Login.this,Menu.class);
                  finish();
                  // this finish() method is used to tell android os that we are done with current //activity now! Moving to other activity
                  startActivity(ii);
                  return json.getString(TAG_MESSAGE);
              }else{
  
                  return json.getString(TAG_MESSAGE);
  
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return null;
      }
      /**
       * Once the background process is done we need to  Dismiss the progress dialog asap
       * **/
      protected void onPostExecute(String message) {
  
          pDialog.dismiss();
          if (message != null){
              Toast.makeText(Login.this, message, Toast.LENGTH_LONG).show();
          }
      }
  }
  </code></pre>
  
  <p>Any ideas? 
  Thanks,
  Yoshi</p>