Am very new to Android programming, so sorry if this is a simple problem.
I’m trying to create a form to input user data, and I keep getting the following error:
“Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@6279d588”
This is what my xml looks like for the layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:isScrollContainer="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">"
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="top">
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a test\nsecond line\n"/>
<EditText android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:maxLength="30"
android:maxLines="1"
android:hint="@string/compose_name"></EditText>
<Button
android:id="@+id/new_contact_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/submit" />
</LinearLayout>
</ScrollView>
And here is what my class file looks like:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_contact);
//Set up handlers for input text
//nameField = (EditText) findViewById(R.id.name);
//name = nameField.getText().toString();
final EditText nameField = (EditText) findViewById(R.id.name);
nameField.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
String strNicknameToSave = nameField.getText().toString();
// TODO: Save Nickname setting (strNicknameToSave)
return true;
}
return false;
}
});
submitButton = (Button) findViewById(R.id.new_contact_button);
// Set up click listeners for all the buttons
submitButton.setOnClickListener(this);
}
If I get rid of the EditText field, then it works fine. Also it ran perfectly just once, but I haven’t been able to repeat that (all I did in the meantime was delete another layout that isn’t being used).
Thanks for your help.
Don’t declare nameField as ‘final’ – see if that works.
EDIT: Ah, OK sorry, I wasn’t thinking straight. Have your Activity implement the listener instead of creating it inline and have nameField as an instance member…