2014-11-19 5 views
18

작동하지 :안드로이드 대해서는 imeOptions = "actionDone"나는 안드로이드 앱의 로그인 화면을 얻으려고 노력하고 있고 지금까지 내 코드입니다

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:orientation="vertical"> 

     <EditText 
      android:id="@+id/username" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Username" 
      android:inputType="text" 
      android:singleLine="true" 
      android:imeOptions="actionNext"> 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/password" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:singleLine="true" 
      android:imeOptions="actionDone" /> 

     <Button 
      android:id="@+id/buttonLaunchTriage" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="@string/login" /> 
    </LinearLayout> 



</RelativeLayout> 

내가 그것을 실행하려고 키보드 오른쪽을 보여줍니다 키를 입력했지만 암호를 입력 한 후에 완료를 시도하면 아무 일도 일어나지 않습니다. 이 버튼을 처리하기 위해 이것을 사용하고 있습니다 :

private void setupLoginButton() { 
    Button launchButton = (Button) findViewById(R.id.buttonLaunchTriage); 
    launchButton.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      EditText username = (EditText) findViewById(R.id.patient_start_userName_value); 
      EditText password = (EditText) findViewById(R.id.patient_start_password_value); 

      try { 
       if(TriageApplicationMain.validateUser(username.getText().toString(),password.getText().toString(),getApplicationContext())) 
       { 
       Toast.makeText(StartActivity.this, 
         "Launching Triage Application", Toast.LENGTH_SHORT) 
         .show(); 
       startActivity(new Intent(StartActivity.this, MainActivity.class)); 
       } 

       else 
        { 
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
          StartActivity.this); 


         // set dialog message 
         alertDialogBuilder 
          .setMessage("Incorrect Credentials") 
          .setCancelable(false) 
          .setPositiveButton("OK",new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog,int id) { 
            // if this button is clicked, close 
            // current activity 
           dialog.cancel();  
           } 
           }); 


          // create alert dialog 
          AlertDialog alertDialog = alertDialogBuilder.create(); 

          // show it 
          alertDialog.show(); 

        } 
       } 


      catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }); 

} 

나는 많은 코드를 알고 있지만, 누군가가 나를 도와 줄 수 있다면 좋을 것입니다. 이것은 학교 프로젝트를위한 것입니다.

추신 : 나는 이것을 게시하기 전에 Google을 통해 단호한 시간을 검색했습니다. 그렇게하지 않으면 비판하지 마십시오. 유용하다고 생각되는 링크를 찾으면 공유하십시오.

+0

? 키보드 자체를 숨기거나 로그인을 진행 하시겠습니까? – waqaslam

+0

나는 동일한 문제에 직면 해 있습니다. 추가 할 내용은 다음과 같습니다. android : imeActionLabel = "완료" android : singleLine = "true" 여기에 대한 답변은 입니다. http://stackoverflow.com/questions/5578991/actiondone -imeoption-doesnt-work-on-edittext-in-android-2-3/5579944 # 5579944 –

답변

29

사용자가 키보드에서 "완료"를 클릭 할 때 수행 할 동작을 구현하기 위해 EditText에 대해 OnEditorActionListener를 설정해야합니다.

따라서, 당신은 같은 코드를 작성해야합니다

password.setOnEditorActionListener(new OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     if (actionId == EditorInfo.IME_ACTION_DONE) { 
      // Do whatever you want here 
      return true; 
     } 
     return false; 
    } 
}); 

은 Qianqian가 올바른지 android developer site

+0

답에 감사드립니다. 나는 다소 stackoverflow에서 한동안 떨어졌다.지금 다시 :) – Mak

19

에서 자습서를 참조하십시오. 코드는 EditorAction 이벤트가 아니라 버튼 클릭 이벤트 만 수신합니다.

일부 전화 공급 업체가 DONE 동작을 제대로 구현하지 않을 수 있음을 추가하고 싶습니다. 내가 예를 들어, 레노버 A889과 검사를하지, 그 휴대 전화가 작업을 완료 누르면 EditorInfo.IME_ACTION_DONE를 전송하지, 항상 (EditorInfo.IME_ACTION_UNSPECIFIED 그래서 난 사실 또한

myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) 
    { 
    boolean handled=false; 

    // Some phones disregard the IME setting option in the xml, instead 
    // they send IME_ACTION_UNSPECIFIED so we need to catch that 
    if(EditorInfo.IME_ACTION_DONE==actionId || EditorInfo.IME_ACTION_UNSPECIFIED==actionId) 
    { 
     // do things here 

     handled=true; 
    } 

    return handled; 
    } 
}); 

은 "처리"플래그를주의 같은 끝낼 Qianqian를 전송 그 부분을 설명하지 않았다). 상위 OnEditorActionListener가 다른 유형의 이벤트를 수신하고있는 것일 수 있습니다. 메서드가 false를 반환하면이 이벤트를 처리하지 못했음을 의미하며 다른 이벤트로 전달됩니다. 당신이 진실을 돌려 준다면 그것은 당신이 그것을 처리/소비했음을 뜻하며 다른 사람들에게 전가되지는 않을 것입니다.

+2

감사 나는 정확히 IME_ACTION_SEND 대신 IME_ACTION_UNSPECIFIED를 얻고있다 – flaviodesousa

+1

이것은 올바른 대답이어야한다 – HendraWD

24

EditText에 android:inputType="..."을 그냥 추가하십시오. 그것은 일할 것이다!! :)

4

사용 android:inputType="Yours"

android:lines="1" 
android:imeOptions="actionDone" 
0

귀하는 사용자가 키보드에서 "완료"를 클릭 할 때 수행 할 작업을 구현하기 위해 글고 치기 위해 OnEditorActionListener 설정해야합니다.

0

많은 일을 시도하면, 이것은 나를 위해 일한 것입니다 :

android:maxLines="1" 
    android:inputType="text" 
    android:imeOptions="actionDone" 
정확히 무슨 당신이 "완료"에서 기대 소프트 입력 키보드에서
+0

이것은 질문에 대한 대답을 제공하지 않는다. 충분한 [평판] (https://stackoverflow.com/help/whats-reputation)이 있으면 [모든 게시물에 주석 달기] (https://stackoverflow.com/help/privileges/comment) 할 수 있습니다. 대신, [질문자의 설명이 필요없는 답변을 제공하십시오] (https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- i-do- 대신). - [리뷰에서] (리뷰/저품절 포스트/18007334) –