2013-06-17 3 views
0

У меня есть активность, которая запускает серию popupWindows через LayoutInflater. У одного из них есть куча EditTexts в нем, и по какой-то причине я не могу заставить мягкую клавиатуру запускаться, когда они сфокусированы. Однако, если я переключу его с popupWindow на alertDialogue.Builder, он работает отлично.Почему мягкая клавиатура появляется для alertDialog.Builder, но не для popupWindow (android)?

Почему это и как я могу заставить его работать как popupWindow?

код AlertDialogue:

AlertDialog.Builder pop_up = new AlertDialog.Builder(this); 
pop_up.setView(this.getLayoutInflater().inflate(R.layout.signup_layout, null)); 
pop_up.show(); 

код PopupWindow:

LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() 
    .getSystemService(LAYOUT_INFLATER_SERVICE); 
View popupView = layoutInflater.inflate(R.layout.signup_layout, null); 
PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.MATCH_PARENT, 
    LayoutParams.MATCH_PARENT); 
popupWindow.showAtLocation(view, 1, 0, 0); 

и XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#C417375E" 
    android:gravity="center" 
    android:orientation="vertical" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/popup_background" 
     android:focusableInTouchMode="true" 
     android:orientation="vertical" 
     android:padding="15dp" > 

     <Button 
      android:id="@+id/back_button" 
      android:layout_width="150dp" 
      android:layout_height="40dp" 
      android:background="@drawable/popup_background" 
      android:text="Back" 
      android:textColor="#ffffff" 
      android:textSize="20sp" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="4dp" 
      android:text="Email or Phone Number" 
      android:textColor="#ffffff" 
      android:textSize="30sp" /> 

     <EditText 
      android:id="@+id/email_textField" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textEmailAddress" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="4dp" 
      android:text="Choose a Password" 
      android:textColor="#ffffff" 
      android:textSize="30sp" /> 

     <EditText 
      android:id="@+id/password_textField" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textPassword" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="4dp" 
      android:text="Confirm Password" 
      android:textColor="#ffffff" 
      android:textSize="30sp" /> 

     <EditText 
      android:id="@+id/confirm_password_textField" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textPassword" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="4dp" 
      android:text="Zip Code(optional)" 
      android:textColor="#ffffff" 
      android:textSize="30sp" /> 

     <EditText 
      android:id="@+id/zipcode_textField" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="number" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingLeft="4dp" 
      android:text="Your First Name (optional)" 
      android:textColor="#ffffff" 
      android:textSize="30sp" /> 

     <EditText 
      android:id="@+id/name_textField" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="textPersonName" /> 

     <Button 
      android:id="@+id/done_button" 
      android:layout_width="150dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="10dp" 
      android:background="@drawable/popup_background" 
      android:onClick="onClick_thanksForSigningUp" 
      android:text="Done" 
      android:textColor="#ffffff" 
      android:textSize="20sp" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Я думаю, что вы не связали свой edittext с java ...... используя «findviewbyid» .... попробуйте его ... могучая работать ... – ASP

+0

попробовать запустить после удаления этой строки 'android: focusableInTouchMode = "true" 'из вашего xml-кода linearlayout. – ASP

+0

, к сожалению, он все еще не работает. Похоже, я переведу весь свой код в диалоги. – user1623346

ответ

0

Попробуйте как это ..... для всех ваших Edittexts.

EditText edt = (EditText) popupView.findviewbyid(R.id.name_textField); 

Надеюсь, он сработает. Спасибо.

+0

Это просто позволяет мне получить доступ к EditText из java-кода. Добавление этой строки не изменяет поведение клавиатуры. Есть ли вызов метода, который мне нужно сделать в EditText, чтобы клавиатура отображалась при использовании всплывающего окна? Если да, почему бы мне не сделать это из AlertDialog? – user1623346