2017-06-08 50 views
0

我有一個彈出窗口,在點擊活動按鈕時調用,此彈出窗口中有一個edittext,im試圖在EditText中輸入後點擊Enter鍵調用搜索功能。但控制永遠不會進入OnEditorActionListener我也試過setOnKeyListener。OnEditorActionListener未啓動EditText在彈出窗口中

這是彈出窗口代碼:

private PopupWindow initiatePopupWindow(int i) { 
try { 
    mInflater = (LayoutInflater) getApplicationContext() 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View layout = mInflater.inflate(R.layout.rowsearch, null); 
View viewone = layout.findViewById(R.id.blankone); 
View viewtwo = layout.findViewById(R.id.blanktwo); 
searchedit = (EditText)layout.findViewById(R.id.search_edit); 
//  searchedit.setImeActionLabel("Go", KeyEvent.KEYCODE_ENTER); 
//  mDropdown.setFocusable(true); 
//  mDropdown.update(); 
//  searchedit.setFocusableInTouchMode(true); 
searchedit.requestFocus(); 
searchedit.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
       @Override 
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
        if (actionId == EditorInfo.IME_ACTION_DONE) { 
         // Search function to be called here 
         Log.d("search","search"); 
         searchfunc(); 

         return true; 
        } 
        return false; 
       } 
      }); 
layout.measure(View.MeasureSpec.UNSPECIFIED, 
        View.MeasureSpec.UNSPECIFIED); 
      mDropdown = new PopupWindow(layout, FrameLayout.LayoutParams.MATCH_PARENT, 
        FrameLayout.LayoutParams.MATCH_PARENT,true); 

      mDropdown.showAsDropDown(linearLayout,5,5); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return mDropdown; 

} 

這是佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="140dp" 
    android:id="@+id/blankone"> 

</View> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    android:orientation="vertical" 
    android:padding="20dp" 
    android:background="@drawable/white_menu"> 


     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textColorHint="#b5b5b5" 
      android:id="@+id/search_edit" 
      android:imeOptions="actionDone" 
      android:hint="what can we help you find?"/> 

    </LinearLayout> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/blanktwo"> 

</View> 

</LinearLayout> 

我試過很多東西像setfocusable(真),但似乎沒有任何工作,我想searchfunc() ;在EditText中敲入回車鍵時被調用。

回答

0

向EditText添加android:inputType="text"解決了問題。