我是片段的新手。
在Activity中,我有两个onClick方法:
如何更改将方法覆盖为片段的onclick?
private void searchMobileNumber() {
mRecyclerView.addOnItemTouchListener(new SelectExistingOrNewNoFragment.RecyclerTouchListener(PostpaidRegistrationActivity.this, mRecyclerView, new SelectExistingOrNewNoFragment.ClickListener() {
@Override
public void onClick(View view, int position) {
selectedPostion = position;
mob_number_detail_lyt.setVisibility(View.GONE);
mobile_no_head_lyt.setVisibility(View.VISIBLE);
mobile_number_success.setImageDrawable(getResources().getDrawable(R.drawable.validation_correct));
if (simCardFirstTime) {
simCardFirstTime = false;
final Intent intent = new Intent(PostpaidRegistrationActivity.this, MyScanActivity.class);
intent.putExtra("ocrType", "Barcode");
intent.putExtra("message", "Please scan your SIM card");
startActivityForResult(intent, MposConstants.SIMCARD_FIRST_TIME);
}
}
}
答案 0 :(得分:0)
如果我清楚这一点,你有两个按钮。其中一个是开始fragment
或用它做某事......你只需要一个switch
个案。另外,对案例使用R
类。
使用view.getId()
代码:
@Override
public void onClick(View view, int position) {
switch(view.getId()){
case R.id.fragment_button:
// do something with fragment
break;
default: break;
}
}