2011-05-09 3 views
4

나는 전형적인 로그인 화면을 가지고있다. imeOptions를 사용하여 한 필드에서 다른 필드로 사용자 "탭"을 허용하고 마지막 필드 (암호)에서 actionDone을 ​​사용할 수있었습니다. 바로 소프트 키보드를 닫습니다. 이상적으로는 "로그인"을 자동으로 클릭하는 것이 좋습니다. 거기에 어떤 것이 내장되어 있습니까?Android imeOptions and auto-pressing 로그인 버튼

답변

1
public class Main extends Activity 
{ 
    private final static String USERNAME = "user1"; 
    private final static String PASSWORD = "12345678"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.page1); 

    final EditText usernameInput = (EditText) findViewById(R.id.username); 
    EditText passwordInput = (EditText) findViewById(R.id.password); 
    passwordInput.addTextChangedListener(new TextWatcher() 
    { 
     @Override 
     public void afterTextChanged(Editable input) 
     { 
     if (USERNAME.equals(usernameInput.getText().toString()) && PASSWORD.equals(input.toString())) 
     { 
      setContentView(R.layout.page2); 
     } 
     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) 
     { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) 
     { 

     } 
    }); 
    } 
}

page1.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="username:" /> 
    <EditText 
     android:id="@+id/username" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="password:" /> 
    <EditText 
     android:id="@+id/password" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout>

이 실제로 자신의 질문에 올바른 암호가있는 경우이 단지 자동 로그를 응답하지 않습니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Login successful." /> 
</LinearLayout>
+1

page2.xml 입력. 그 짧은 또는 잘못 철자 (그러나 더 긴 경우) 당신이 그것을 bruteforce 수있는 큰 보안 위험이 될 수도, – Mgamerz