我是Android開發中的新成員。我試圖從片段值傳遞給活動,但這麼多的嘗試後,我無法得到答案......如何將片段中的值傳遞給活動
這是我的片段:
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;
}
而這正是我想要的類通過數值
它看起來像你的問題是不完整 – Manza
是代碼給你一個錯誤,如果是的話顯示我們 –