2016-12-06 5 views
0

Я хочу реализовать диалоговое окно для ввода пароля и проверки его. Теперь я определил класс диалога, а функция oncreate будет устанавливатьContentView, используя мой собственный файл макета.Как добавить слушателя в edittext в пользовательский диалог

MyDialog class { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.ms_pdf_viewer_password_layout); 
    } 
} 

Вот XML

<EditText 
    android:imeOptions="actionGo" 
    android:layout_marginLeft="4dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textPassword" 
    android:textColorHint="@color/hint_text_color" 
    android:textColor="@color/text_color" 
    android:textSize="12dp" 
    android:hint="Please enter the password" 
    android:ems="10" 
    android:id="@+id/editText"/> 

создать объект диалога во фрагменте, и я хочу, чтобы обрабатывать кнопку ввода прессовое и проверки ввода пароля, но слушатель не работает, ActionId не может быть распечатанный. Я думаю, что, возможно, я не получу объект editText правильно.

Dialog dialog = new PdfPasswordDialog(getActivity()); 
View view = inflater.inflate(R.layout.ms_pdf_viewer_password_layout, container, false); 
EditText editText = (EditText) dialog.findViewById(R.id.editText); 



editText.setOnEditorActionListener(
      new TextView.OnEditorActionListener() { 
       @Override 
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
        Log.i(sClassTag,"actionID is "+actionId); 

Как добавить слушателя в edittext в пользовательский диалог для ввода пароля? Любая помощь приветствуется.

+0

вы можете использовать 'TextWatcher' –

ответ

0

Если вы хотите изменить или манипулировать текст или проверить введенный текст при вводе нового персонажа, вы можете использовать TextWatcher здесь пример для вас:

TextWatcher watcher = 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) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       // when the change is done 
      } 
     }; 
0

Используйте этот код

final Dialog dialog = new Dialog(getActivity()); 
dialog.setContentView(R.layout.ms_pdf_viewer_password_layout); 
dialog.setTitle("Any Title You Want"); 
EditText editText = (EditText) dialog.findViewById(R.id.editText); 

Теперь попробуйте onClickListener.

0

Я, наконец, разрешаю его с помощью EditText editText = dialog.findViewById (R.id.edittext); после dialog.show().

 Смежные вопросы

  • Нет связанных вопросов^_^