das hilft mir leider nicht. Das Problem ist, dass der Fokus automatisch beim Öffnen des Dialogs auf dem EditText liegt. Wenn ich anschließend das EditText nochmal antippe, dann öffnet sich auch die Tastatur. Ohne weiteren Code.
Hier ist mal der Code um meinen Dialog zu öffnen:
1final Dialog dialog = new Dialog(this);
2 dialog.setContentView(R.layout.dialog_new_meeting);
3 dialog.setTitle(R.string.create_meeting);
4 dialog.setCancelable(true);
5 dialog.setCanceledOnTouchOutside(true);
6 final EditText editText = (EditText) dialog
7 .findViewById(R.id.new_meeting_dialog_text);
8
9 Button send_button = (Button) dialog
10 .findViewById(R.id.new_meeting_dialog_send);
11 send_button.setOnClickListener(new OnClickListener() {
12 @Override
13 public void onClick(View v) {
14 String meetingTitle = editText.getText().toString();
15 int restricted = (((CheckBox) dialog
16 .findViewById(R.id.new_meeting_dialog_restricted))
17 .isChecked()) ? 1 : 0;
18 if (!meetingTitle.equals(""))
19 newMeeting(meetingTitle, restricted, MyGlobals.userId, 0,
20 dialog);
21 else
22 Toast.makeText(getApplicationContext(),
23 getString(R.string.error_noValues),
24 Toast.LENGTH_SHORT).show();
25 }
26 });
27
28 editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
29 @Override
30 public void onFocusChange(View v, boolean hasFocus) {
31 if (hasFocus) {
32 dialog.getWindow()
33 .setSoftInputMode(
34 WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
35 }
36 }
37 });
38
39 dialog.show();
Und hier das XML des Dialogs:
1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="fill_parent"
3 android:layout_height="fill_parent" >
4
5 <EditText
6 android:id="@+id/new_meeting_dialog_text"
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:layout_alignParentLeft="true"
10 android:layout_marginLeft="5dip"
11 android:layout_marginRight="5dip"
12 android:maxLength="60"
13 android:singleLine="true"
14 android:text="" >
15
16 <requestFocus />
17 </EditText>
18
19 <CheckBox
20 android:id="@+id/new_meeting_dialog_restricted"
21 android:layout_width="fill_parent"
22 android:layout_height="wrap_content"
23 android:layout_alignLeft="@+id/new_meeting_dialog_text"
24 android:layout_below="@+id/new_meeting_dialog_text"
25 android:text="@string/restricted_meeting" >
26 </CheckBox>
27
28 <Button
29 android:id="@+id/new_meeting_dialog_send"
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:layout_alignLeft="@+id/new_meeting_dialog_restricted"
33 android:layout_below="@+id/new_meeting_dialog_restricted"
34 android:text="@string/add" >
35 </Button>
36
37</RelativeLayout>
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.