2017-07-14 123 views
1

我正在使用默認Android Gboard keyboard。但在EditText上使用inputType="number"時出現問題。顯示的鍵盤,但類型值不顯示在EditText,也沒有在TextWatcher中獲得任何類型的值。Gboard鍵盤:數字inputType在ListView中的EditText上不起作用

ListView元素的EditText如下所示:

<EditText 
    android:id="@+id/editTextChecked" 
    android:layout_width="150dp" 
    android:layout_height="60dp" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_gravity="center" 
    android:gravity="center"  
    android:inputType="number" 
    android:textColor="#000000" /> 

ListView被定義爲:

<ListView 
    android:id="@+id/listViewDialog" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/bottom" 
    android:layout_below="@+id/editTextSearch" 
    android:background="@android:color/white" 
    android:divider="@android:color/darker_gray" 
    android:dividerHeight="1dp" /> 

這是我的TextWather代碼: -

holder.etCheck.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      Log.e("text",""+s.toString()); 
     } 

     @Override 
     public void afterTextChanged(Editable s) { 

     } 
    }); 
+0

你可以顯示你的'TextWatcher'代碼。 – arcticwhite

回答

0

的它與TextWatcher是一樣的與ListView s一起工作得非常好。你必須定義自己的TextWatcher這樣的:

private class MyCustomEditTextListener implements TextWatcher { 
    private int position; 

    public void updatePosition(int position) { 
     this.position = position; 
    } 

    @Override 
    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { 
     // do your operations here. 
    } 

    @Override 
    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { 
    } 

    @Override 
    public void afterTextChanged(Editable editable) { 
     Logger.e(TAG, "After" + editable.toString()); 
    }  
} 

和內部getView()做到這一點:

((Viewholder) holder).myCustomEditTextListener.updatePosition(position); 

最後你viewHolder內初始化你EditText和定製TextWatcher添加到它。

相關問題