亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android小程序實現(xiàn)個人信息管理系統(tǒng)

 更新時間:2020年05月22日 16:52:53   作者:adorable_  
這篇文章主要為大家詳細介紹了Android小程序實現(xiàn)個人信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)個人信息管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

要求:使用SQLite實現(xiàn)個人信息管理系統(tǒng),個人信息包括姓名,年齡,性別以及學歷

(1)DBHelper.java代碼如下:

package com.example.system;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

 private static final String DB_NAME ="people.db";
 private static final String TBL_NAME="Message";
 private SQLiteDatabase db;

 public DBHelper(Context c){
 super(c,DB_NAME,null,2);
 }

 @Override
 public void onCreate(SQLiteDatabase db){
 this.db=db;
 String CREATE_TBL="create table Message(_id integer primary key autoincrement,name text,age text,sex text,edu text)";
 db.execSQL(CREATE_TBL);
 }

 public void insert(ContentValues values){
 SQLiteDatabase db=getWritableDatabase();
 db.insert(TBL_NAME, null, values);
 db.close();
 }

 public Cursor query(){
 SQLiteDatabase db=getWritableDatabase();
 Cursor c=db.query(TBL_NAME, null, null, null, null, null, null);
 return c;
 }

 @Override
 public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
 // TODO Auto-generated method stub

 }

}

(2)MainActivity.java代碼如下:

package com.example.system;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

 private TextView textview;
 private Button btn1,btn2;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 textview = (TextView)findViewById(R.id.textview);
 btn1 = (Button)findViewById(R.id.btn1);
 btn2 = (Button)findViewById(R.id.btn2);

 //添加監(jiān)聽器
 btn1.setOnClickListener(new OnClickListener() {

 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub

 Intent intent = new Intent(MainActivity.this,AddActivity.class);
 startActivity(intent);
 }
 });

 btn2.setOnClickListener(new OnClickListener() {

 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub

 Intent intent = new Intent(MainActivity.this,QueryActivity.class);
 startActivity(intent);

 }
 });

 }
}

對應布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <TextView
 android:id="@+id/textview"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="90dp"
 android:gravity="center"
 android:text="個人信息管理系統(tǒng)"
 android:textSize="40dp" />

 <Button
 android:id="@+id/btn2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/btn1"
 android:layout_alignBottom="@+id/btn1"
 android:layout_alignParentRight="true"
 android:layout_marginRight="60dp"
 android:text="查詢" />

 <Button
 android:id="@+id/btn1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/textview"
 android:layout_marginLeft="60dp"
 android:layout_marginTop="100dp"
 android:text="添加" />
</RelativeLayout>

(3)AddActivity.java代碼如下:

package com.example.system;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends Activity {
 //聲明組件
 private EditText name,age,sex,edu;
 private Button add;


 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_add);

 name=(EditText)findViewById(R.id.name);
 age=(EditText)findViewById(R.id.age);
 sex=(EditText)findViewById(R.id.sex);
 edu=(EditText)findViewById(R.id.edu);
 add=(Button)findViewById(R.id.ButtonAdd);

 //根據(jù)ID 獲取組件
 add.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub

 String name1=name.getText().toString();
 String age1=age.getText().toString();
 String sex1=sex.getText().toString();
 String edu1=edu.getText().toString();

 //封裝信息
 ContentValues values=new ContentValues();
 values.put("name", name1);
 values.put("age", age1);
 values.put("sex", sex1);
 values.put("edu", edu1);

 DBHelper helper=new DBHelper(getApplicationContext());
 helper.insert(values);

 Intent intent = new Intent(AddActivity.this,MainActivity.class);
 startActivity(intent);

 }
 });

 } 
}

對應布局文件如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 android:padding="10dp">

 <TableLayout
 android:id="@+id/TableLayout"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:stretchColumns="1">

 <TableRow 
 android:id="@+id/TableRow01"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">

 <TextView 
 android:id="@+id/textview1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="姓名"/>
 <EditText 
 android:id="@+id/name"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text=""/> 
 </TableRow>

 <TableRow 
 android:id="@+id/TableRow02"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"> 

 <TextView 
 android:id="@+id/textview2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="年齡"/>
 <EditText 
 android:id="@+id/age"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text=""/>
 </TableRow>

 <TableRow 
 android:id="@+id/TableRow03"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"> 

 <TextView 
 android:id="@+id/textview3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="性別"/>
 <EditText 
 android:id="@+id/sex"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text=""/>
 </TableRow>

 <TableRow 
 android:id="@+id/TableRow04"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"> 

 <TextView 
 android:id="@+id/textview4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="學歷"/>
 <EditText 
 android:id="@+id/edu"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text=""/>
 </TableRow>

 <Button 
 android:id="@+id/ButtonAdd"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="添加"/>
 </TableLayout>
</LinearLayout>

(4)QueryActivity.java代碼如下:

package com.example.system;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class QueryActivity extends ListActivity{

 private ListView listview=null;

 @Override
 public void onCreate(Bundle savedInstanceState){
 super.onCreate(savedInstanceState);

 this.setTitle("瀏覽信息");

 listview=getListView();

 final DBHelper helper=new DBHelper(this);

 Cursor c=helper.query();

 String[] from={"_id","name","age","sex","edu"};

 int[] to={R.id.text0,R.id.text1,R.id.text2,R.id.text3,R.id.text4};

 SimpleCursorAdapter adapter=new SimpleCursorAdapter(this, R.layout.activity_query, c, from, to);
 listview.setAdapter(adapter);
 }
}

對應布局文件如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
<TextView
 android:id="@+id/text0"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />

<TextView
 android:id="@+id/text1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
<TextView
 android:id="@+id/text2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
<TextView
 android:id="@+id/text3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
<TextView
 android:id="@+id/text4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
</LinearLayout>

實現(xiàn)效果如下:

更多學習資料請關注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 淺談Android中Drawable使用知識總結

    淺談Android中Drawable使用知識總結

    本篇文章主要介紹了淺談Android中Drawable使用知識總結,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Android 圖片選擇詳解及實例代碼

    Android 圖片選擇詳解及實例代碼

    這篇文章主要介紹了 Android 圖片選擇詳解及實例代碼的相關資料,需要的朋友可以參考下
    2016-12-12
  • Flutter TV Android端開發(fā)技巧詳細教程

    Flutter TV Android端開發(fā)技巧詳細教程

    這篇文章主要為大家介紹了Flutter TV Android端開發(fā)技巧詳細教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • CoordinatorLayout的使用如此簡單(Android)

    CoordinatorLayout的使用如此簡單(Android)

    這篇文章主要為大家詳細介紹了Android CoordinatorLayout的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android HandlerThread案例詳解

    Android HandlerThread案例詳解

    這篇文章主要介紹了Android HandlerThread案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下
    2021-08-08
  • Android屬性動畫之ValueAnimator代碼詳解

    Android屬性動畫之ValueAnimator代碼詳解

    這篇文章主要介紹了Android屬性動畫之ValueAnimator代碼詳解,分享了相關代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Android控件之AnalogClock與DigitalClock用法實例分析

    Android控件之AnalogClock與DigitalClock用法實例分析

    這篇文章主要介紹了Android控件之AnalogClock與DigitalClock用法,以實例形式分析了Android時鐘控件AnalogClock和DigitalClock用于顯示時間的具體使用技巧,需要的朋友可以參考下
    2015-09-09
  • 詳解Android中的SharedPreferences

    詳解Android中的SharedPreferences

    這篇文章主要介紹了Android中的SharedPreferences,包括 SharedPreferences的特點和使用方法,需要的朋友可以參考下
    2017-05-05
  • android apk反編譯到java源碼的實現(xiàn)方法

    android apk反編譯到java源碼的實現(xiàn)方法

    Android由于其代碼是放在dalvik虛擬機上的托管代碼,所以能夠很容易的將其反編譯為我們可以識別的代碼,本文將詳細介紹,需要的朋友可以參考下
    2012-12-12
  • flutter?material?widget組件之信息展示組件使用詳解

    flutter?material?widget組件之信息展示組件使用詳解

    這篇文章主要為大家詳細介紹了flutter?material?widget組件之信息展示組件的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08

最新評論