Building a Generic Login Page

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby kali » Tue Jun 02, 2009 7:42 am

hello pogz
i got error at statement:


showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "


the error is :

The method showAlert(String, String, String, boolean) is undefined for the type new View.OnClickListener(){}

pls help me.
kali
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 27, 2009 1:31 pm

Top

regarding sqlite database

Postby jana » Wed Aug 05, 2009 7:35 am

Hi Guys ,

I'm making a login page for my application.
I need to check the login username and password against the database



i have total 4classes
loginform(usname ---------
password -------
login register )
register(it consists of some text and edit fields and also one button(save)
after user enter all fileds ,when he clicks save button ,it will store in database)
main
Dbclass


i created all the above classes and coded ui part and also databse creation

when user first time means , he will register first and then by checking username and password he will login


but all these fields r in database
how to store them dynamically
and how to retrieve and update and delete the records
pls send the code for this application
my mailid is vuruvakilinaidu@gmail.com


thanks and regards
janardhan
jana
Freshman
Freshman
 
Posts: 7
Joined: Tue Aug 04, 2009 8:27 am

pls check the scenario

Postby jana » Wed Aug 05, 2009 7:39 am

Hi Guys ,

I'm making a login page for my application.
I need to check the login username and password against the database



i have total 4classes
loginform(usname ---------
password -------
login register )
register(it consists of some text and edit fields and also one button(save)
after user enter all fileds ,when he clicks save button ,it will store in database)
main
Dbclass


i created all the above classes and coded ui part and also databse creation

when user first time means , he will register first and then by checking username and password he will login


but all these fields r in database
how to store them dynamically
and how to retrieve and update and delete the records
pls send the code for this application
my mailid is vuruvakilinaidu@gmail.com


thanks and regards
janardhan



plusminus wrote:Hey pogz,

you do that with the following BB-Tags-Style:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. [ syntax = " language " ] YOUR_CODE [ / syntax ]
  2. where     language == java      or     language == xml      or    most other languages...
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Yes you are right, I will do a posting-guide or a kinda 'template' tomorrow :!:

Regards,
plusminus
jana
Freshman
Freshman
 
Posts: 7
Joined: Tue Aug 04, 2009 8:27 am

Postby jmf » Thu Jan 28, 2010 12:01 am

@kali - I got the same error as that. I right clicked it and used the show fix option.

In order to get the program to run and compile it also suggested I change 'EditText id="@+id/txt_password"' to 'EditText android:id="@+id/txt_password"'.

I did this to all instances and it now compiles and runs but nothing happens when you hit the login button.

I'm kind of fumbling around in the dark really and am not sure of what I'm doing...anyone know why the login button wouldn't be doing anything?
jmf
Freshman
Freshman
 
Posts: 2
Joined: Wed Jan 27, 2010 10:36 pm

i am using min SDK version is 7 and i am using 2.1 api level

Postby mohammed.gouse » Mon Apr 05, 2010 9:28 am

venkat wrote:Hi cybersat,
you may be forgot to update the main.xml file here.
just copy main.xml file above :roll: and past it in your main.xml file . it will be in inside the res-->layout.
i have attached full project here. have a look.

regards,
venkat
[font=Arial Black] [/font]
mohammed.gouse
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Apr 05, 2010 9:22 am

Re: Building a Generic Login Page

Postby Sivan » Mon Jul 12, 2010 5:29 pm

Hi pogz...

Nice tutorial, I really liked it , but there is 1 prob
The layout is perfect but the java coding has a problem

When I run the application on the Emulator, Its running but when i click Login its doing nothing......


This is your Code:
________________________________________________________________________________________

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package pogz.test;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9.  
  10. /**
  11.  *  Application Name: <span class="posthilit">Generic</span> <span class="posthilit">Login</span> Screen for the Android Platform (back end)
  12.  *  Description: This is <span class="posthilit">a</span> <span class="posthilit">generic</span> <span class="posthilit">login</span> screen which catches the username and password values
  13.  *  Created on: November 23, 2007
  14.  *  Created by: Pogz Ortile
  15.  *  Contact: pogz(at)redhat(dot)polarhome(dot)com
  16.  *  Notes: The string values for username and password are assigned to sUserName and sPassword respectively
  17.  *              You are free to distribute, modify, and wreck for all I care. GPL ya!
  18.  * */
  19.  
  20. public class PogzTest01 extends Activity {
  21.     /** Called when the activity is first created. */
  22.     @Override
  23.    
  24.     public void onCreate(Bundle icicle) {
  25.         super.onCreate(icicle);
  26.        
  27.         // load up the layout
  28.         setContentView(R.layout.main);
  29.        
  30.         // get the button resource in the xml file and assign it to <span class="posthilit">a</span> local variable of type Button
  31.         Button launch = (Button)findViewById(R.id.login_button);
  32.        
  33.         // this is the action listener
  34.         launch.setOnClickListener( new OnClickListener()
  35.         {
  36.                
  37.                 public void onClick(View viewParam)
  38.                 {
  39.                         // this gets the resources in the xml file and assigns it to <span class="posthilit">a</span> local variable of type EditText
  40.                 EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
  41.                 EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
  42.                
  43.                 // the getText() gets the current value of the text box
  44.                 // the toString() converts the value to String data type
  45.                 // then assigns it to <span class="posthilit">a</span> variable of type String
  46.                 String sUserName = usernameEditText.getText().toString();
  47.                 String sPassword = passwordEditText.getText().toString();
  48.                        
  49.                 // this just catches the error if the program cant locate the GUI stuff
  50.                 if(usernameEditText == null || passwordEditText == null){
  51.                     showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "
  52.                               + "EditView in main.xml", "Oh shit!", false);
  53.                 }else{
  54.                         // display the username and the password in string format
  55.                         showAlert("Logging in", "Username: " + sUserName + "nPassword: " + sPassword , "Ok", true);
  56.                         }
  57.                 }
  58.         }
  59.        
  60.         ); // end of launch.setOnclickListener
  61.     }
  62. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4

__________________________________________________________________________________________________


And this is my code :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.hello;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.os.Bundle;
  10.  
  11. public class Android extends Activity {
  12.     /** Called when the activity is first created. */
  13.     @Override
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.main);
  17.    
  18.         Button launch = (Button)findViewById(R.id.widget33);
  19.        
  20.         // this is the action listener
  21.         launch.setOnClickListener( new OnClickListener()
  22.         {
  23.                
  24.                 public void onClick(View viewParam)
  25.                 {
  26.                         // this gets the resources in the xml file and assigns it to a local variable of type EditText
  27.                 EditText usernameEditText = (EditText) findViewById(R.id.widget29);
  28.                 EditText passwordEditText = (EditText) findViewById(R.id.widget30);
  29.                
  30.                 // the getText() gets the current value of the text box
  31.                 // the toString() converts the value to String data type
  32.                 // then assigns it to a variable of type String
  33.                 String sUserName = usernameEditText.getText().toString();
  34.                 String sPassword = passwordEditText.getText().toString();
  35.                        
  36.                 // this just catches the error if the program cant locate the GUI stuff
  37.                 if(usernameEditText == null || passwordEditText == null){
  38.                     showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "
  39.                               + "EditView in main.xml", "Oh shit!", false);
  40.                 }else{
  41.                         // display the username and the password in string format
  42.                         showAlert("Logging in", "Username: " + sUserName + "nPassword: " + sPassword , "Ok", true);
  43.                         }
  44.                 }
  45.         }
  46.        
  47.         ); // end of launch.setOnclickListener
  48.     }
  49.  
  50.         protected void showAlert(String string, String string2, String string3,
  51.                         boolean b) {
  52.                 // TODO Auto-generated method stub
  53.                
  54.         }
  55.  
  56. }
  57.    
  58.    
  59.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4




Project Details ::::::

Application Name: Hello Android
Project Name: Hello Android
Package Name: com.hello.android
SDK version : 8 (android 2.2)


Help will be appriciated :)
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Top

Re: Building a Generic Login Page

Postby alesmana » Sun Aug 01, 2010 9:04 am

Sivan wrote:Hi pogz...

Nice tutorial, I really liked it , but there is 1 prob
The layout is perfect but the java coding has a problem

When I run the application on the Emulator, Its running but when i click Login its doing nothing......

Project Details ::::::

Application Name: Hello Android
Project Name: Hello Android
Package Name: com.hello.android
SDK version : 8 (android 2.2)


Help will be appriciated :)


can you show us your android manifest file
alesmana
Freshman
Freshman
 
Posts: 2
Joined: Sun Aug 01, 2010 9:02 am

Re: Building a Generic Login Page

Postby alesmana » Sun Aug 01, 2010 10:05 am

Hi pogz,

great tutorial you have here :)

In any case, I am using android 2.2 and the attached layout xml is no longer work.
Here is mine

[ syntax = "xml" ]
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2009 Joe LaPenna -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:isScrollContainer="true"
android:background="@drawable/foursquare_gradient"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:src="@drawable/main_logo" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="5dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginBottom="15dip"
android:padding="10dip"
android:background="@drawable/purple_plate"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dip"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFF"
android:text="@string/login_get_started" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dip"
android:textColor="#FFF"
android:text="@string/login_get_started_more" />
<EditText
android:id="@+id/phoneEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:textAppearance="@android:style/TextAppearance.Large"
android:hint="@string/phone_number_or_email" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:textAppearance="@android:style/TextAppearance.Large"
android:hint="@string/password" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:enabled="false"
android:textAppearance="@android:style/TextAppearance.Large"
android:text="@string/login_label" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dip"
android:src="@drawable/line" />
<TextView
android:id="@+id/newAccountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:paddingBottom="2dip"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="#FFF"
android:text="@string/need_an_account" />
</LinearLayout>
</LinearLayout>


[ / syntax ]

And in case someone is wondering what the xml file for the manifest should look like, here is mine
[ syntax = "xml" ]

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<your package name>"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".<your activty class name>"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="6" />

</manifest>
[ / syntax ]

and in case someone did not read correction made by sainath

sainath wrote:Hi

I am new to Mobile Development and just recently i started playing with Android.

As i was trying this example in android-sdk-windows-1.0_r2.zip, i am getting an error

"The method showAlert(String, String, String, boolean) is undefined for the type new View.OnClickListener(){}"

so i used Toast instead and it worked,

Toast.makeText(LoginPage.this, "Couldn't find the 'txt_username' or 'txt_password'",
Toast.LENGTH_SHORT).show();

but i want to know whether showAlert Exists in present sdk release or it has been removed or its a user defiend function.




thats all
alesmana
Freshman
Freshman
 
Posts: 2
Joined: Sun Aug 01, 2010 9:02 am

Re: Building a Generic Login Page

Postby Dhr » Thu Aug 19, 2010 12:10 pm

Hello,

Thanks for uploading code for Login Application.

I used it but it shows one error at showAlert();
How to solve it?
Is there any other way to display Alerts in Android.??

I tried to solve the error but after running the application and on clicking the button Login!, it shows nothing.
I mean to say that the Login! button doesn't work.
So how to resolve it.

I m very happy if any one solve it.

Regards/Thanks,
Dhr
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Building a Generic Login Page

Postby anilexotrac » Thu Dec 16, 2010 7:54 pm

hi,
i am very new to android application.
i have made identical login application with same codings.
but whenever i click ok button, its not showing any message. what may be the cause.

hope to hear soon from you.
thanks
anilexotrac
Freshman
Freshman
 
Posts: 2
Joined: Thu Dec 16, 2010 5:55 pm

Re: Building a Generic Login Page

Postby anilexotrac » Thu Dec 16, 2010 8:46 pm

anilexotrac wrote:hi,
i am very new to android application.
i have made identical login application with same codings.
but whenever i click ok button, its not showing any message. what may be the cause.

hope to hear soon from you.
thanks
anilexotrac
Freshman
Freshman
 
Posts: 2
Joined: Thu Dec 16, 2010 5:55 pm

Re: Building a Generic Login Page

Postby wasabi » Mon Aug 22, 2011 9:29 am

does the method showAlert exist in the project (PogzTest01.java) or is it just okay to use a Toast insted? thanks
wasabi
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 22, 2011 9:20 am

Re: Building a Generic Login Page

Postby donut » Tue Aug 30, 2011 5:46 pm

if i click login button it doesnt respond anything,,
donut
Freshman
Freshman
 
Posts: 3
Joined: Tue Aug 30, 2011 5:07 pm

Re: Building a Generic Login Page

Postby donut » Wed Aug 31, 2011 8:42 am

Sivan wrote:Hi pogz...

Nice tutorial, I really liked it , but there is 1 prob
The layout is perfect but the java coding has a problem

When I run the application on the Emulator, Its running but when i click Login its doing nothing......


This is your Code:
________________________________________________________________________________________

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package pogz.test;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9.  
  10. /**
  11.  *  Application Name: <span class="posthilit">Generic</span> <span class="posthilit">Login</span> Screen for the Android Platform (back end)
  12.  *  Description: This is <span class="posthilit">a</span> <span class="posthilit">generic</span> <span class="posthilit">login</span> screen which catches the username and password values
  13.  *  Created on: November 23, 2007
  14.  *  Created by: Pogz Ortile
  15.  *  Contact: pogz(at)redhat(dot)polarhome(dot)com
  16.  *  Notes: The string values for username and password are assigned to sUserName and sPassword respectively
  17.  *              You are free to distribute, modify, and wreck for all I care. GPL ya!
  18.  * */
  19.  
  20. public class PogzTest01 extends Activity {
  21.     /** Called when the activity is first created. */
  22.     @Override
  23.    
  24.     public void onCreate(Bundle icicle) {
  25.         super.onCreate(icicle);
  26.        
  27.         // load up the layout
  28.         setContentView(R.layout.main);
  29.        
  30.         // get the button resource in the xml file and assign it to <span class="posthilit">a</span> local variable of type Button
  31.         Button launch = (Button)findViewById(R.id.login_button);
  32.        
  33.         // this is the action listener
  34.         launch.setOnClickListener( new OnClickListener()
  35.         {
  36.                
  37.                 public void onClick(View viewParam)
  38.                 {
  39.                         // this gets the resources in the xml file and assigns it to <span class="posthilit">a</span> local variable of type EditText
  40.                 EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
  41.                 EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
  42.                
  43.                 // the getText() gets the current value of the text box
  44.                 // the toString() converts the value to String data type
  45.                 // then assigns it to <span class="posthilit">a</span> variable of type String
  46.                 String sUserName = usernameEditText.getText().toString();
  47.                 String sPassword = passwordEditText.getText().toString();
  48.                        
  49.                 // this just catches the error if the program cant locate the GUI stuff
  50.                 if(usernameEditText == null || passwordEditText == null){
  51.                     showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "
  52.                               + "EditView in main.xml", "Oh shit!", false);
  53.                 }else{
  54.                         // display the username and the password in string format
  55.                         showAlert("Logging in", "Username: " + sUserName + "nPassword: " + sPassword , "Ok", true);
  56.                         }
  57.                 }
  58.         }
  59.        
  60.         ); // end of launch.setOnclickListener
  61.     }
  62. }
Parsed in 0.043 seconds, using GeSHi 1.0.8.4

__________________________________________________________________________________________________


And this is my code :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.hello;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.os.Bundle;
  10.  
  11. public class Android extends Activity {
  12.     /** Called when the activity is first created. */
  13.     @Override
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.main);
  17.    
  18.         Button launch = (Button)findViewById(R.id.widget33);
  19.        
  20.         // this is the action listener
  21.         launch.setOnClickListener( new OnClickListener()
  22.         {
  23.                
  24.                 public void onClick(View viewParam)
  25.                 {
  26.                         // this gets the resources in the xml file and assigns it to a local variable of type EditText
  27.                 EditText usernameEditText = (EditText) findViewById(R.id.widget29);
  28.                 EditText passwordEditText = (EditText) findViewById(R.id.widget30);
  29.                
  30.                 // the getText() gets the current value of the text box
  31.                 // the toString() converts the value to String data type
  32.                 // then assigns it to a variable of type String
  33.                 String sUserName = usernameEditText.getText().toString();
  34.                 String sPassword = passwordEditText.getText().toString();
  35.                        
  36.                 // this just catches the error if the program cant locate the GUI stuff
  37.                 if(usernameEditText == null || passwordEditText == null){
  38.                     showAlert("Crap!", "Couldn't find the 'txt_username' or 'txt_password' "
  39.                               + "EditView in main.xml", "Oh shit!", false);
  40.                 }else{
  41.                         // display the username and the password in string format
  42.                         showAlert("Logging in", "Username: " + sUserName + "nPassword: " + sPassword , "Ok", true);
  43.                         }
  44.                 }
  45.         }
  46.        
  47.         ); // end of launch.setOnclickListener
  48.     }
  49.  
  50.         protected void showAlert(String string, String string2, String string3,
  51.                         boolean b) {
  52.                 // TODO Auto-generated method stub
  53.                
  54.         }
  55.  
  56. }
  57.    
  58.    
  59.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4




Project Details ::::::

Application Name: Hello Android
Project Name: Hello Android
Package Name: com.hello.android
SDK version : 8 (android 2.2)


Help will be appriciated :)
donut
Freshman
Freshman
 
Posts: 3
Joined: Tue Aug 30, 2011 5:07 pm

Re: Building a Generic Login Page

Postby donut » Wed Aug 31, 2011 8:43 am

hey i m too facing similar prob as Sivan couuld any1 pls reply me
donut
Freshman
Freshman
 
Posts: 3
Joined: Tue Aug 30, 2011 5:07 pm

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests