Home > Mobile >  Android page jump to fail
Android page jump to fail

Time:01-09

This is the main page, also is my login account page, click on the register account, jump to the registration page, what wrong, however, stop

Package com. Example. Myapp;
The import android. App. The Activity;
The import android. Content. Intent;
The import android. Database. Cursor;
The import android. Database. Sqlite. SQLiteDatabase;
import android.os.Bundle;
The import android. View. The view;
The import android. View. The view. An OnClickListener;
The import android. Widget. The Button;
The import android. Widget. The EditText;
The import android. Widget. TextView;
The import android. Widget. Toast;

Public class LoginActivity extends the Activity implements an OnClickListener {
Private Button btnlogin;
Private Button btnrest;
Private EditText etUserName;
Private EditText etPwd;
Private TextView tvReg;

//define attribute
Private Dbdata Dbdata;
Private SQLiteDatabase sd;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Zh_login);

//register to monitor, find the concerned control
Btnlogin=(Button) the findViewById (R.i db tn_login);
Btnlogin. SetOnClickListener (this);//click event

Btnrest=(Button) the findViewById (R.i db tn_reset);
Btnrest. SetOnClickListener (this);//click event

EtUserName=(EditText) the findViewById (R.i d.e t_username);
EtPwd=(EditText) the findViewById (R.i d.e t_pwd);//click event

TvReg=(TextView) the findViewById (R.i which v_register);
TvReg. SetOnClickListener (this);
//create database
Dbdata=https://bbs.csdn.net/topics/new Dbdata (this);
Sd=Dbdata. GetReadableDatabase ();
}

@ Override
Public void onClick (View v) {

//TODO Auto - generated method stub

Int id=v.g etId ();
String username=etUserName. GetText (). The toString ();
String PWD=etPwd. GetText (). The toString ();

The switch (id) {
Case R.i db tn_login:

//read real user name and password in the database
String SQL="Select * From t_users Where username=? And password=?" ;
String [] ¶s={username and PWD};
Cursor c=sd. RawQuery (SQL, ¶s);

If (c. oveToNext ()) {
//user name and password input correct
Be sad etString chtistina georgina rossetti.british poetess String stunum=(String) (be sad etColumnIndex chtistina georgina rossetti.british poetess ((" stunum "))). The trim ();//the trim () removes white Spaces at the first
Toast. MakeText (this, "right" + stunum, Toast. LENGTH_LONG), show ();
If (stunum. Equals (" the teacher ")) {
//open TeacherActivity
Intent Intent=
The new Intent (this, TeacherActivity. Class);
startActivity(intent);
} else {
//open ScoreActivity
Intent toMain=new Intent (this, scoreActivity. Class);
ToMain. PutExtra (" username ", username);
StartActivity (toMain);
}
} else {
//input error
Toast. MakeText (this, "error", Toast. LENGTH_LONG), show ();
}

break;
Case R.i db tn_reset:
EtUserName. SetText (" ");
EtPwd. SetText (" ");
break;
Case R.i which v_register:
//open the registration form
Intent Intent=
The new Intent (LoginActivity. This, registeredActivity. Class);
startActivity(intent);
break;
}
}



}

This is the registration page. Java source code
Package com. Example. Myapp;

The import android. App. The Activity;
The import android. Content. Intent;
The import android. Database. Cursor;
The import android. Database. Sqlite. SQLiteDatabase;
import android.os.Bundle;
The import android. View. The view;
The import android. View. The view. An OnClickListener;
The import android. Widget. The Button;
The import android. Widget. The EditText;
The import android. Widget. TextView;
The import android. Widget. Toast;

Public class registeredActivity extends the Activity implements an OnClickListener {
Private EditText etUserName;
Private EditText etPwd;
Private EditText etStuNum;
Private EditText etClassId;

Private TextView tv_login;
//database related
Private Dbdata Dbdata;
Private SQLiteDatabase db.
Private Button btnselect;



@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Zh_registered);
//initialize interface
InitView ();
//instantiate database
Dbdata=https://bbs.csdn.net/topics/new Dbdata (this);
The db=Dbdata. GetWritableDatabase ();

//register to monitor
Tv_login=(TextView) the findViewById (R.i which v_back);
Tv_login. SetOnClickListener (this);

}
Private void initView () {
//register to monitor
EtUserName=(EditText) the findViewById (R.i d.e t_username);
EtPwd=(EditText) the findViewById (R.i d.e t_pwd);
EtStuNum=(EditText) the findViewById (R.i d.e t_stunum);
EtClassId=(EditText) the findViewById (R.i d.e t_classId);
//btnSave=(Button) the findViewById (R.i db tn_save);
}

Public void save (View v) {
String UN=etUserName. GetText (). The toString ();
String PWD=etPwd. GetText (). The toString ();
A String of sn=etStuNum. GetText (). The toString ();
String ci=etClassId. GetText (). The toString ();

//2. The stitching a SQL
String SQL="Insert Into t_users (username, password, stunum, every) values ('" + UN + "', '" + PWD +"', '" + sn + "', '" + ci + ") ";
//3. Executing SQL statements
Try {
Db. ExecSQL (SQL);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related