2017-02-28 4 views
0

Hyのみんな、押し戻さXamarinのAndroid

は、私は私のアプリでは、OnKeyDownを使用しようとしているが、私はフラグメント内で使用しようとすると、何が起こるか...私はこの活動での活動を持って、私はそのかけらを持っています他のフラグメントを呼び出すと、戻るボタンを押すと、アプリケーションが閉じる...どうすれば実装できますか?誰かが例を挙げることはできますか?あなたはFragments間で移行されると

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); 
     } 
    } 
} 
+1

あなたがフラグメント間で移行している場合、あなたのFragmentTransactionの一部 FragmentTransaction TX = fragmentManager.beginTransation()としてaddToBackStack()を呼び出します。tx.replace(R.id.fragment、new MyFragment()).addToBackStack( "tag").commit(); 私はそれがあなたのために働くことを願って....! –

+0

解決に感謝します!その仕事。 –

答えて

0

addToBackStack()を呼び出す:

FragmentTransaction FragmentTransaction tx = fragmentManager.beginTransation(); 
tx.replace(R.id.fragment, new MyFragment()).addToBackStack("tag").commit(); 
関連する問題