一個Android架構下實現登入和Google檢索的應用程式

來源:互聯網
上載者:User

1.      需求設計
在Android的資料庫建立一個login表,包括密碼和賬戶兩個欄位

實現兩個activity應用程式,其中一個,提供兩個入力框,分別輸入密碼和賬戶,並且實現登入check

登入成功之後,跳轉到第二個Activity,在其上實現一個入力框,根據輸入的參數,到google上檢索

 

2.     
 

 

 

3.      主要代碼
3.1    第一個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    第二個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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.