0
海兰大家,回压Xamarin的Android
我想在我的应用程序使用的onkeydown,但我想一个片段中使用,会发生什么......我在这个活动活动,我有一个片段调用其他片段,当按下按钮时,应用程序关闭...我如何实现它?有人可以举个例子吗?
namespace Uer.Fragments
{
public class Login : Fragment
{
//Statement Objects
private TextView lblNewUser;
private LinearLayout lnlContainer;
private EditText edtEmail;
private EditText edtPassword;
private Button btnLogin;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
View view = inflater.Inflate(Resource.Layout.Login, container, false);
lnlContainer = view.FindViewById<LinearLayout>(Resource.Id.lnlContainer);
lblNewUser = view.FindViewById<TextView>(Resource.Id.lblNewUser);
edtEmail = view.FindViewById<EditText>(Resource.Id.edtEmail);
edtPassword = view.FindViewById<EditText>(Resource.Id.edtPassword);
btnLogin = view.FindViewById<Button>(Resource.Id.btnLogin);
lblNewUser.Click += LblNewUser_Click;
btnLogin.Click += BtnLogin_Click;
return view;
}
private void BtnLogin_Click(object sender, EventArgs e)
{
string email = edtEmail.Text;
string password = edtPassword.Text;
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
AlertDialog.Builder alert = new AlertDialog.Builder(Activity);
alert.SetTitle("Campos Vazios");
alert.SetMessage("Email ou Senha estao vazios");
alert.SetNeutralButton("OK", (senderAlert, args) =>
{
alert.Dispose();
});
alert.Create();
alert.Show();
} else if (!email.Equals("[email protected]") || !password.Equals("admin"))
{
AlertDialog.Builder alert = new AlertDialog.Builder(Activity);
alert.SetTitle("Email ou Senha Invalidos");
alert.SetMessage("Voce digitou email ou senha incorreto");
alert.SetNeutralButton("OK", (senderAlert, args) =>
{
alert.Dispose();
});
alert.Create();
alert.Show();
}
else
{
Intent intent = new Intent(Activity, typeof(MainActivity));
this.StartActivity(intent);
}
}
private void LblNewUser_Click(object sender, EventArgs e)
{
var transaction = Activity.SupportFragmentManager.BeginTransaction();
transaction.SetCustomAnimations(Resource.Animation.slide_in,
Resource.Animation.slide_out, Resource.Animation.slide_in,
Resource.Animation.slide_out);
transaction.Replace(Resource.Id.lnlContainer, new Register(), "Register");
transaction.Commit();
//Intent intent = new Intent(Activity, typeof(RegisterActivity));
//this.StartActivity(intent);
}
}
}
当你片段之间的转换,调用addToBackStack()作为 FragmentTransaction TX = fragmentManager.beginTransation()你FragmentTransaction的一部分; tx.replace(R.id.fragment,new MyFragment()).addToBackStack(“tag”).commit(); 我希望它适合你....! –
感谢您的解决方案!是工作。 –