2017-06-08 5 views
0

J'ai une fenêtre popUp qui est appelée en cliquant sur un bouton en activité, cette popup a un edittext à l'intérieur, im essayant d'appeler la fonction de recherche en tapant enter après avoir tapé EditText. Mais le contrôle ne vient jamais à l'intérieur de OnEditorActionListener j'ai aussi essayé setOnKeyListener.OnEditorActionListener n'est pas lancé pour EditText dans la fenêtre contextuelle

C'est le code de fenêtre:

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; 

} 

Ceci est la mise en page:

<?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> 

J'ai essayé beaucoup de choses comme setfocusable (vrai), mais rien ne semble je travaille veux searchfunc() ; être appelé en appuyant sur la touche Entrée dans le EditText. L'ajout de android:inputType="text" à EditText a résolu le problème.

Répondre

0