2016-11-23 4 views
0

ログインフォームを作成しようとしています。これは私のパスワードフィールドのxmlです:ログインするにはキーボードのgoキーを2回押す必要があります

<android.support.design.widget.TextInputLayout 
     android:id="@+id/password" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     app:errorEnabled="true"> 

     <android.support.design.widget.TextInputEditText 
      android:id="@+id/password_input" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/password" 
      android:inputType="textPassword" 
      android:imeOptions="actionGo"/> 
    </android.support.design.widget.TextInputLayout> 

と私はこのように行くのキールックスを聞いていloginActivity:私はキーボードがポップアップ表示パスワードフィールドを押した後、私が持っている場合は

@OnClick(R.id.password_input) 
public void Start() { 
    EditText editText = (EditText) findViewById(R.id.password_input); 
    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      boolean handled = false; 
      if (actionId == EditorInfo.IME_ACTION_GO) { 
       logIn(); 
       handled = true; 
      } 
      return handled; 
     } 
    }); 
} 

goキーを2回押してlogIn()関数を呼び出します。それの理由は何か、この問題をどうやって解決するのですか?

答えて

2

変更あなたの条件:あなたのxmlレイアウトの追加

<EditText 
     android:id="@+id/edtInput" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:imeOptions="actionGo" 
     android:inputType="textPassword" /> 
私はテストケースを作成していた

EditText editText = (EditText) findViewById(R.id.password_input); 
    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 

      if (actionId == EditorInfo.IME_ACTION_GO) { 
       logIn(); 

      } 
      return false; 
     } 
    }); 

は、このいずれかに確認してください

あなたのアクティビティ/フラグメントコードで確認:

EditText edtInput = (EditText) findViewById(R.id.edtInput); 
     edtInput.setImeOptions(EditorInfo.IME_ACTION_GO); 
     edtInput.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if (actionId == EditorInfo.IME_ACTION_GO) { 
        Toast.makeText(MainActivity.this, " GO ", Toast.LENGTH_SHORT).show(); 
       } 
       return false; 
      } 
     }); 

これで動作していることを確認してくれました。これもうまくいくはずです。

は最後に、私は何の使用量が存在しない場合、あなたはコードの

@OnClick(R.id.password_input) 
public void Start() { 

行を削除してくださいすることができ、これはすべてが発生させていない問題であり、我々がやっていた愚かな過ちとソリューションを持って。

(あなたのonCreateに直接このコードを追加します。)活動の、のEditTextにクリックイベントを与える必要はありません:

EditText editText = (EditText) findViewById(R.id.password_input); 
    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      if (actionId == EditorInfo.IME_ACTION_GO) { 
       logIn(); 

      } 
      return false; 
     } 
    }); 
+0

その後の答えを受け入れる動作している場合。 –

+0

Enterキーを2回押してログインする必要があります。ワンクリックでログイン操作が必要になります。 –

+0

@Al Noman私はそれを1回のクリックで機能させる必要があります。これは、Enterキーを2回押すと既に起こっています。 –

1

このようにif条件を置き換えてください。このようなonEditorActionで

if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { 
     Log.e(TAG, "enter_key_pressed"); 
    } 
0
@OnClick(R.id.password_input) 
public void Start() { 
    if (doublePressed) { 
     //your intent or Operation 
      return; 
    } 
    this.doublePressed = true; 
    Toast.makeText(this, "Please click again to do”, Toast.LENGTH_SHORT).show(); 

    new Handler().postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      doublePressed=false;      
     } 
    }, 2000); 
} 
0
@OnClick(R.id.password_input) 
public void Start() { 
EditText editText = (EditText) findViewById(R.id.password_input); 
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 

     if (actionId == EditorInfo.IME_ACTION_GO) { 
      logIn(); 
      return true; 
     } 
     return false; 
    } 
}); 
} 
+0

アプリの最初の起動時にEnterキーを2回押してください。 –

+0

TextInputEditTextに問題があり、EditTextに変更しています... – Bhavnik