我想開發一個Log在頁面中,我有用戶名,密碼和一個按鈕。當我第一次點擊按鈕時,什麼也沒有發生,但是當我第二次點擊按鈕時,它就能正常工作。我很困惑,它爲什麼會發生?按鈕不調用OnClickListener與第一次點擊
activity_login.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_bg"
tools:context=".LoginActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:layout_margin="30dp" >
<EditText
style="@style/EditText1"
android:id="@+id/userEditText"
android:layout_marginBottom="50dp"
android:inputType="textNoSuggestions"
android:singleLine="true"
android:hint="username" />
<EditText
style="@style/EditText1"
android:id="@+id/passEditText"
android:inputType="textPassword"
android:layout_marginBottom="50dp"
android:hint="password" />
<Spinner
android:id="@+id/locationSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:popupBackground="#ffffff"
style="@style/EditText1"
android:layout_marginBottom="50dp" />
<Button
style="@style/Button1"
android:focusable="true"
android:focusableInTouchMode="true"
android:onClick="onLoginClick"
android:text="continue"
/>
loginActivity.java
@SuppressLint("DefaultLocale")
public void onLoginClick(View view) {
String username = mUserEditText.getText().toString();
String password = mPassEditText.getText().toString();
String location = mLocationData.get(
mLocationSpinner.getSelectedItemPosition()).toLowerCase();
if (username.isEmpty() || password.isEmpty()) {
CreatorMessenger
.getInstance()
.showMessage(this, "Error!!",
"You need to enter username and password both to continue!!");
return;
}
User user;
user = new User(username);/*
* }
*/
user.setLocation(location);
AppManager.getInstance().setLoggedInUser(user);
APICaller.getInstance().login(username, password, location);
}
使用Logger在logcat中查看它是否正在輸入方法。你會看到它不是focusableInTouchMode參數。 – Jorgeblom
那我該怎麼做,請幫幫我? –
也許我對這個類似問題的回答可能有所幫助:http://stackoverflow.com/a/42092582/1617737 –