1. Requirement Design
Create a login table in the Android database, including the password and account fields.
Implement two activity applications, one of which provides two in-force boxes, respectively entering the password and account, and implementing login check
After successful login, jump to the second Activity, implement an in force box on it, according to the input parameters, search on google
2.
3. Main Code
3.1 code of the first Activity
Public class Android1 extends Activity {
Private Button mButton1;
Private TextView mTextView1;
Private TextView mTextView2;
Private String user = new String ();
Private String password = new String ();
Private DBHelper dbHelper;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MTextView1 = (TextView) findViewById (R. id. EditText01 );
MTextView2 = (TextView) findViewById (R. id. EditText02 );
DbHelper = new DBHelper (this, "TestDB ");
CreateTable ();
}
Public void onClick (View v ){
// TODO Auto-generated method stub
User = mTextView1.getText (). toString ();
Password = mTextView2.getText (). toString ();
Boolean result = selectTable (user, password );
Log. d ("Android1", "the result is" + result );
If (result = true ){
Intent intent = new Intent ();
Intent. setClass (Android1.this, Android2.class );
StartActivity (intent );
}
}
Public void createTable (){
SQLiteDatabase db = dbHelper. getWritableDatabase ();
Db
. ExecSQL ("create table if not exists LOG (user varchar primary key, password varchar )");
}
Public boolean selectTable (String user, String password ){
SQLiteDatabase db = dbHelper. getWritableDatabase ();
Try {
Cursor result = db. rawQuery (
"Select * from LOG where user =? AND password =? ",
New String [] {user, password });
Log. d ("Android1", "count is" + result. getCount ());
If (result. getCount ()! = 0 ){
Result. close ();
Db. close ();
Return true;
} Else {
Result. close ();
Db. close ();
Return false;
}
} Catch (SQLException ex ){
Log. d ("Android1", "select table failure ");
Return false;
}
}
}
3.2 code of the Second Activity
Public class Android2 extends Activity {
Private TextView mTextView1;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. search );
MTextView1 = (TextView) findViewById (R. id. EditTextSearch );
}
Public void onClick (View v ){
String key = mTextView1.getText (). toString ();
& N