title: How to make edittext autofocus after showing a Toast?
body: <p>I have a EditText that reads a 13 digit barcode. What I want to do is to keep the virtual keyboard shown on the screen and the EditText to always have focus. The following code let me write the barcode and search for a product when enter key is pressed, and it works well. But if I type a barcode with less then 13 digits or the barcode typed does not exist in my database, I want to show the user a Toast, informing him of it. After displaying the Toast, I want the EditText to gain focus again automatically, letting the user just type the barcode again. After showing the Toast, I tried the requestFocus() method, but it didn't work. The soft keyboard is always shown, but after the Toast, I can't type in the EditText again unless I touch on the EditText. How can I do this?</p>
  
  <pre><code>    final EditText procura_codbar = (EditText)
                  findViewById(R.id.procurar_produto_codbar);
      procura_codbar.setOnKeyListener(new View.OnKeyListener() {
  
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
  
              if ((event.getAction() == KeyEvent.ACTION_DOWN)
                      &amp;&amp; (keyCode == KeyEvent.KEYCODE_ENTER)) {
  
                  String codbar = procura_codbar.getText().toString();
                  if (codbar.length()&lt;13){   
                      Toast.makeText(MainActivity.this,
                             "type a 13 digit barcode",
                             Toast.LENGTH_LONG).show();
                  }
                  else{
                      if (bdh!=null){
                          bdh.closedb(); bdh.close();
                      }
                      bdh = new DBHelper(MainActivity.this);
                      Log.i("CODBAR", codbar);
                      produto prod_ = bdh.getProduto(codbar);
                      if (prod_!=null){
                          showDialogPreco(prod_);
                          procura_codbar.setText("");
                      }else{
                          Toast.makeText(MainActivity.this,
                                                       "Product not found",
                                                       Toast.LENGTH_SHORT).show();
                          procura_codbar.setSelection(codbar.length());
                      }
                  }
                  procura_codbar.requestFocus();
                  procura_codbar.setSelection(codbar.length());
              }
  
              return false;
          }
      });
  </code></pre>
  
  <p>And here is the XML:</p>
  
  <pre><code>&lt;EditText
      android:id="@+id/procurar_produto_codbar"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:inputType="textNoSuggestions|number"
      android:textSize="22sp"
      android:maxLength="13"
      android:layout_toRightOf="@+id/tv_procura_codbar" &gt;
  
      &lt;requestFocus /&gt;
  &lt;/EditText&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Messing with this, I found the problem. Heres the solution:</p>
  
  <pre><code>return true;
  </code></pre>
  
  <p>Now it works...</p>