I have a simple layout with two EditTexts and a button. When the
Activity starts, the first EditText automatically gets focus and the
virtual keyboard is shown. When I click the button, the second
EditText gets focus because the first one is gone. If I click the
button again, the second EditText is gone, and I would expect the
virtual keyboard to go away. Clicking the button one more time shows
that #getCurrentFocus() now returns null. However, the virtual
keyboard is still displayed.

Is this by design? Do I need to manually hide and display the virtual
keyboard myself when I hide and unhide Views?

  public void onClick(View v) {
    android.util.Log.i("tag", getCurrentFocus().toString());  //
prints text_box1, text_box2, and then null
    if (findViewById(R.id.edit_text1).getVisibility() == View.VISIBLE)
{
      findViewById(R.id.edit_text1).setVisibility(View.GONE);
      findViewById(R.id.edit_text1).clearFocus();
    } else {
      findViewById(R.id.edit_text2).setVisibility(View.GONE);
      findViewById(R.id.edit_text2).clearFocus();
    }
  }

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  >
  <EditText android:id="@+id/edit_text1"
  android:layout_width="300dip"
  android:layout_height="64dip" />
  <EditText android:id="@+id/edit_text2"
  android:layout_width="300dip"
  android:layout_height="64dip" />
  <Button
  android:layout_width="300dip"
  android:layout_height="64dip"
  android:text="Click me"
  android:onClick="onClick" />
</LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to