简体   繁体   中英

Require password after app start

currently developing an android application. when application starts up I want it to require a user name and password to enter. haven't had any luck searching. currently have main layout with just enter button and an edit text for password. couldn't post image of layout here is code.

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

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/welcome" />
<Button
    android:id="@+id/btnEnter"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/enter"></Button>
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="@string/signPass"
    android:gravity="center_horizontal" 
    android:inputType="textPassword" >

    <requestFocus /> 
</EditText>
<Button
    android:id="@+id/btnInitiate"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/initiate"></Button>

</LinearLayout>

You can take in the user input for username and password and compare it to database records. You can then handle the result via an if-else statement, if there's a positive match, then you can proceed by calling another activity. Otherwise, you show a toast to notify the user about the mismatch.

I strongly suggest you go over basic Android tutorials and come back when you stumble upon other problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM