I’m very new to programming in Android, but have been struggling all day with a problem and would appreciate your help.
I’m trying to create a form to get user information (essentially a new contact) which is accessed from the menu. When I click the button to create the new form, I get the following error:
“Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@626fd5e0”
This is my code:
The menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/search"
android:title="@string/settings_search"
android:alphabeticShortcut="@string/settings_shortcut_search" />
<item android:id="@+id/new_contact"
android:title="@string/settings_new"
android:alphabeticShortcut="@string/settings_shortcut_new" />
</menu>
The code for calling the new activity:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_contact:
//activities to create a new account
//startActivity(new Intent(this, Prefs.class));
Intent i = new Intent(MainActivity.this, NewContact.class);
startActivity(i);
//addSaver("String");
return true;
case R.id.search:
return true;
// More items go here (if any) ...
}
return false;
}
The view for the new contact activity:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
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"/>
<Button
android:id="@+id/new_contact_button"
android:layout_height="wrap_content"
android:text="@string/submit" />
</LinearLayout>
</ScrollView>
And the code for the new activity:
public class NewContact extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_contact);
// Set up click listeners for all the buttons
View newContactButton = findViewById(R.id.new_contact_button);
newContactButton.setOnClickListener(this);
}
Bizarrely if I comment out the button from the class and from the xml then it works correctly and opens up the new activity (but of course I can’t do anything with that activity).
In your button xml code, you are missing
add that and give it a shot.