在对话框中单击按钮时导航到不同的页面

时间:2015-11-02 16:42:15

标签: android

注册后,当我按下登录按钮时,会打开一个用户名和密码的对话框,之后在对话框中再次出现一个登录按钮,如果成功显示吐司,我想在吐司后导航到不同的页面 但问题是再次从对话框登录后我必须按第一页的登录按钮

 public void signIn(View V)
    {
        final Dialog dialog = new Dialog(MainActivity.this);
        dialog.setContentView(R.layout.sign_in);
        dialog.setTitle("Login");

        // get the Refferences of views
        final EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);
        final  EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin);

        Button btnSignIn=(Button)dialog.findViewById(R.id.buttonSignIn);

        // Set On ClickListener
        btnSignIn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // get The User name and Password
                String userName=editTextUserName.getText().toString();
                String password=editTextPassword.getText().toString();

                // fetch the Password form database for respective user name
                String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);


                // check if the Stored password matches with  Password entered by user
                if(password.equals(storedPassword))
                {

                    Button next=(Button) findViewById(R.id.buttonSignIn);
                    next.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            Intent myIntent = new Intent(view.getContext(), After_signin.class);
                            startActivityForResult(myIntent, 0);
                        }

                    });
                    Toast.makeText(MainActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
                    dialog.dismiss();

                }
                else
                {
                    Toast.makeText(MainActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
                }
            }
        });

        dialog.show();
    }

我的第一页的xml文件是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    android:background="#d34754df">




    <Button
        android:id="@+id/buttonSignIN"
        android:layout_width="96dp"
        android:layout_height="wrap_content"

        android:text="Sign In"
        android:onClick="signIn"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />


    <Button
        android:id="@+id/buttonSignUP"
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:text="Sign Up"
        android:layout_below="@+id/buttonSignIN"
        android:layout_alignLeft="@+id/buttonSignIN"
        android:layout_alignStart="@+id/buttonSignIN" />




    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="guest"
        android:textAllCaps="true"
        android:onClick="guest"

        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/guest"
        />

</RelativeLayout>

对于sign_in页面,在对话框中打开

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editTextUserNameToLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="User Name"
        android:ems="10" >
        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editTextPasswordToLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        android:hint="Password" />

    <Button
        android:id="@+id/buttonSignIn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Sign In" />

</LinearLayout>

在这方面的任何帮助都会很棒。

0 个答案:

没有答案