An Android application that implements logon and Google Retrieval

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.