title: Set Focus on EditText
body: <p>I have an EditText-Field and set an OnFocusChangeListener for it. When it has lost focus, a method is called, which checks the value of the EditText with one in the database. If the return-value of the method is true, a toast is shown and the focus should get back on the EditText again. The focus should always get back on the EditText and the keyboard should show, until the return-value of the method is false.</p>
  
  <p>EDIT: I think, I haven't made my real problem perfectly clear yet: No other Item on the Screen should be able to edit, until the value of the EditText is edited to a value, which makes the method "checkLiganame(liganame)" return false. Only the EditText-Field should be editable.</p>
  
  <p>here is my code (which doesn't work for me):</p>
  
  <pre><code>final EditText Liganame = (EditText) findViewById(R.id.liganame);
  
      Liganame.setOnFocusChangeListener(new OnFocusChangeListener() {
  
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
              if (!hasFocus) {
  
                  String liganame = Liganame.getText().toString();
  
  
                  if (checkLiganame(liganame)) {
                      Toast toast = Toast.makeText(CreateTableActivity.this,
                              "Dieser Liganame ist bereits vergeben",
                              Toast.LENGTH_SHORT);
                      toast.show();
                      Liganame.requestFocus();
                  }
              }
  </code></pre>
  
  <p>and the method:</p>
  
  <pre><code>public boolean checkLiganame(String liganame) {
      boolean found = false;
  
      DatabaseHelper databaseHelper = new DatabaseHelper(this);
      SQLiteDatabase db = databaseHelper.getReadableDatabase();
  
      Cursor cursor = db.query("liga", new String[] { "liganame" },
              "liganame = '" + liganame + "'", null, null, null, null);
      Log.i("Liganame: ", String.valueOf(cursor));
  
      db.close();
      if (cursor != null) {
          found = true;
      }
  
      return found;
  }
  </code></pre>
  
  <p>This code leads to the following result: After the EditText has lost focus, the focus jumps back to EditText, but I can't edit the text anymore.</p>
  
  <p>EDIT2: Changed my code. Scenario:</p>
  
  <p>I click on the first EditText and put a String in it, which is already in the database. The toast is showing. Now I can't edit my String anymore. I click "next" on the keyboard and the focus stays on the first EditText. I try to edit my String, but nothing happens. Instead my new String is showing in the second EditText. I click on the back-arrow of my device and reclick on the first and second EditText --> no keyboard is showing.</p>
  
  <p>Here is my new Code:</p>
  
  <pre><code>public class CreateTableActivity extends Activity implements
      OnFocusChangeListener {
  
  private EditText Liganame, Mannschaftsanzahl;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.create_league);
  
      Liganame = (EditText) findViewById(R.id.liganame);
      Liganame.setOnFocusChangeListener(this);
      Mannschaftsanzahl = (EditText) findViewById(R.id.mannschaftsanzahl);
      Mannschaftsanzahl.setOnFocusChangeListener(this);
  
      final Button save_button = (Button) findViewById(R.id.create_tabelle_speichern_button);
  
      OnClickListener mCorkyListener = new OnClickListener() {
          public void onClick(View v) {
              ButtonClick();
          }
      };
      save_button.setOnClickListener(mCorkyListener);
  
  
  
  }
  
  @Override
  public void onFocusChange(View v, boolean hasFocus) {
      String liganame = Liganame.getText().toString();
  
      if (checkLiganame(liganame)) {
          if (Liganame.requestFocus()) {
              getWindow()
                      .setSoftInputMode(
                              WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
              Mannschaftsanzahl.clearFocus();
              Toast.makeText(CreateTableActivity.this,
                      "Dieser Liganame ist bereits vergeben",
                      Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre>