2012-06-09 47 views
0

我已經實現了一個帶有EditText元素的彈出對話框。我無法在屏幕上顯示Softkeyboard,也無法填充EditText元素。這個問題是衆所周知的,但我仍然無法正常工作。我已經嘗試瞭解決這個問題的不同選項 - 請參閱onCreate方法。謝謝。EditText:SoftKeyboard在自定義AlertDialog

public class MyPopup extends AbstractPlainPopup { 
    protected Context _context; 

    public CreatePlaylistPopup(Context context) { 
     super(context); 
     _context = context; 
    } 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     LayoutInflater inflater = getLayoutInflater(); 
     View container = inflater.inflate(R.layout.popup_new_playlist, null); 

     final EditText titleInput = (EditText) container.findViewById(R.id.my_text_view); 
     titleInput.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 
       if (hasFocus) { 
        InputMethodManager mgr = (InputMethodManager) _context.getSystemService(Context.INPUT_METHOD_SERVICE); 
        mgr.showSoftInput(titleInput, InputMethodManager.SHOW_IMPLICIT); 
        //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 
        //MyPopup.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 



       } 
      } 
     }); 
     container.findViewById(R.id.cancelButton).setOnClickListener(
       new onCancelClick()); 
     container.findViewById(R.id.createButton).setOnClickListener(
       new onCreateClick()); 
     setContentView(container); 
    } 
    abstract public class AbstractPlainPopup extends AlertDialog implements Observable { 

     public final static int CANCEL = 0; 
     public final static int OK = 1; 

     protected int _state; 

     protected ArrayList<Observer> observers = new ArrayList<Observer>(); 

     public AbstractPlainPopup(Context context){ 
      super(context); 
     } 


    public AbstractPlainPopup(Context context, boolean cancelable, OnCancelListener cancelListener) { 
     super(context, cancelable, cancelListener); 
    } 

回答

0

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

使用此中的onCreate(),而不是內部的焦點變化監聽

+0

..still不起作用。請,如果你對你的建議有信心 - 你可能想發佈你的樣本。我真的很感激。 – user1384991

2
Dialog dialog = new Dialog(this, R.style.Theme_Dialog_Transparent);       
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.enter_details); 
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
+0

是的,但它不是AlertDialog對象。無論如何,除了爲邊界增加透明度之外,我也做了同樣的事情 – user1384991