我是一名Android开发新手,我正在尝试从Fragment传递值到Activity,但是经过多次尝试后,我仍然无法得到答案...
这是我的Fragment代码:
public OtpGentation(int OTP)
{
this.OTP =OTP;
}
public OtpGentation(String number1, String email1, String password)
{
number = number1;
mail = email1;
pass = password;
}
public OtpGentation() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootview = inflater.inflate(R.layout.otp, container, false);
Bundle bundle = getArguments();
new OTPAsyncManager().execute();
etxotp =(EditText)rootview.findViewById(R.id.etxotp);
btnNext = (Button) rootview.findViewById(R.id.nextToOTP);
btnCancel =(Button) rootview.findViewById(R.id.cancel);
//etxotp.setText(OTP);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
if (etxotp.getText().toString().equals(""))
{
Toast.makeText(getContext(), "Please Enter OTP ", Toast.LENGTH_SHORT).show();
}
else
{
int enteredOtp = Integer.parseInt(etxotp.getText().toString());
if (enteredOtp ==OTP)
{
Toast.makeText(getContext(), "OTP Matched", Toast.LENGTH_SHORT).show();
Bundle bun = new Bundle();
bun.putString("no",number);
bun.putString("ma",mail);
bun.putString("pa",pass);
Intent subintent = new Intent(getContext(),SubmitRegistration.class);
subintent.putExtras(bun);
startActivity(subintent);
}
else
{
Toast.makeText(getContext(), "Please Enter Correct OTP ", Toast.LENGTH_SHORT).show();
}
}
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
fragmentManager = getActivity().getSupportFragmentManager();
HomeScreen fragmentOne = new HomeScreen();
fragmentManager
.beginTransaction()
.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.replace(R.id.content_frame, fragmentOne)
.addToBackStack("")
.commit();
}
});
return rootview;
}
这是我想要传递值的类