Building a Generic Login Page
What you will learn: Create a simple generic login page to be used for different applications
Difficulty: 1.0 of 5

What it will look like:

Description: This is a generic login page with the GUI elements in the XML and the even handlers in the java file. This is pretty straightforward and has complete comments on what it does. The message box just displays the data from the text boxes. You could change it to an actual login event or any event you want. Just post up if you a have problems! Enjoy.
main.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- Application Name: Generic Login Screen for the Android Platform (GUI)
- Description: This is a generic login screen which catches the username and password values
- Created on: November 23, 2007
- Created by: Pogz Ortile
- Contact: pogz(at)redhat(dot)polarhome(dot)com
- Notes: The username_text is the written text and the txt_username is the textbox. Same goes for the password
- You are free to distribute, modify, and wreck for all I care. GPL ya!
- -->
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView id="@+id/welcome_text"
- android:text = "Welcome to My Application!n"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- />
- <TextView id="@+id/username_text"
- android:text = "username:"
- android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/welcome_text"
- />
- <EditText id="@+id/txt_username"
- android:layout_height="wrap_content"
- android:layout_width="250px"
- android:layout_centerHorizontal="true"
- android:layout_below="@+id/username_text"
- android:singleLine="true" />
- <TextView id="@+id/password_text"
- android:text = "password:"
- android:layout_centerHorizontal="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/txt_username"
- />
- <EditText id="@+id/txt_password"
- android:password="true"
- android:layout_height="wrap_content"
- android:layout_width="250px"
- android:layout_centerHorizontal="true"
- android:layout_below="@+id/password_text"
- android:singleLine="true" />
- <Button id="@+id/login_button"
- android:text="Login!"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_below="@+id/txt_password"
- />
- </RelativeLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
YOUR_MAIN_APP.java
Using java Syntax Highlighting
- package pogz.test;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- /**
- * Application Name: Generic Login Screen for the Android Platform (back end)
- * Description: This is a generic login screen which catches the username and password values
- * Created on: November 23, 2007
- * Created by: Pogz Ortile
- * Contact: pogz(at)redhat(dot)polarhome(dot)com
- * Notes: The string values for username and password are assigned to sUserName and sPassword respectively
- * You are free to distribute, modify, and wreck for all I care. GPL ya!
- * */
- public class PogzTest01 extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- // load up the layout
- setContentView(R.layout.main);
- // get the button resource in the xml file and assign it to a local variable of type Button
- Button launch = (Button)findViewById(R.id.login_button);
- // this is the action listener
- launch.setOnClickListener( new OnClickListener()
- {
- public void onClick(View viewParam)
- {
- // this gets the resources in the xml file and assigns it to a local variable of type EditText
- EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
- EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
- // the getText() gets the current value of the text box
- // the toString() converts the value to String data type
- // then assigns it to a variable of type String
- String sUserName = usernameEditText.getText().toString();
- String sPassword = passwordEditText.getText().toString();
- // this just catches the error if the program cant locate the GUI stuff
- if(usernameEditText == null || passwordEditText == null){
- showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "
- + "EditView in main.xml", "Oh shit!", false);
- }else{
- // display the username and the password in string format
- showAlert("Logging in", "Username: " + sUserName + "nPassword: " + sPassword , "Ok", true);
- }
- }
- }
- ); // end of launch.setOnclickListener
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


I do appreciate, that you posted your tutorial here 




