0
得到了兩個空的Activites(A和B),它們在Activity A的ViewPager中只保存了兩個片段。 我沒有代碼錯誤,一切看起來都很好。 當我午餐我的應用程序,並點擊按鈕,沒有反應。我只是想記錄的東西,但仍然沒有發生。OnClick在片段內沒有被觸發
我正在使用ButterKnife,到目前爲止一切都很完美。我得到了幾乎相同的片段,它表現良好,但片段B內的OnClick沒有工作。我嘗試添加一些更多的OnClick方法,但都沒有工作對於我來說.XML看起來不錯,看起來和片段A幾乎一樣。
片段B並不複雜,它只是三個TextViews和Button。
這裏是代碼爲我的片段B:
公共類ForgotPasswordFragmentComplete擴展BaseFragment 實現基本視點{
private Realm realm;
private Email model;
@Bind(R.id.btn_resend)
AppCompatButton resendEmail;
@Inject
ForgotPasswordPresenter presenter;
@OnClick(R.id.btn_resend)
public void resendButton() {
Log.d("ResendOnclick", "Checking OnClickMethod ");
Realm realm2 = getRealm();
RealmQuery<Email> queryUserResend = realm2.where(Email.class);
Email resultResend = queryUserResend.findFirst();
ForgotPasswordPayload forgotPayload = new ForgotPasswordPayload(resultResend.getUsername());
this.presenter.subscribe(forgotPayload);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DaggerForgotPasswordCompletedComponent.builder()
.applicationComponent(
((AndroidApplication) getActivity().getApplication()).getApplicationComponent())
.forgotPasswordCompletedModule(new ForgotPasswordCompletedModule())
.build()
.inject(this);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
protected void onCreateViewWidgetInitialization(View view) {
super.onCreateViewWidgetInitialization(view);
}
@Override
public void onStart() {
super.onStart();
getEmail();
}
public void getEmail(){
Realm realm = getRealm();
RealmQuery<Email> queryUser = realm.where(Email.class);
Email result1 = queryUser.findFirst();
resendEmailTxt = (AutoResizeTextView) getView().findViewById(R.id.resend_user_email);
if (resendEmailTxt != null) {
this.resendEmailTxt.setText(result1.getUsername());
}
}
@Override
public void onDestroy() {
super.onDestroy();
realm.close();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_forgot_password_fragment_complete, container, false);
}
@Override
protected int getFragmentLayoutId() {
return R.layout.fragment_forgot_password_fragment_complete;
}
這不是幫助。看起來像我的按鈕是不可點擊的 –