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 매개 변수를 beacuse 아니라는 것을 볼 수 있습니다. – Jorgeblom
그래서 어떻게해야합니까, 제발 도와주세요 ?? –
어쩌면이 비슷한 질문에 대한 내 대답은 도움이 될 수 있습니다 : http://stackoverflow.com/a/42092582/1617737 –