日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

Android Studio實現(xiàn)簡單的通訊錄

瀏覽:22日期:2022-09-19 08:59:05

網(wǎng)上找的一個單頁面通訊錄,修改之后將添加聯(lián)系人和修改/刪除聯(lián)系人分為兩個獨立頁面

Android Studio實現(xiàn)簡單的通訊錄Android Studio實現(xiàn)簡單的通訊錄Android Studio實現(xiàn)簡單的通訊錄

MainActivity

package com.example.test; import androidx.appcompat.app.AppCompatActivity;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.text.method.ScrollingMovementMethod;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ MyHelper myHelper; private TextView tvShow; private Button btnAdd; private Button btnQuery; private Button btnUpdate; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);myHelper = new MyHelper(this);init(); } private void init(){tvShow = (TextView)findViewById(R.id.tv_show);btnAdd = (Button)findViewById(R.id.btn_add);btnQuery = (Button)findViewById(R.id.btn_query);btnUpdate = (Button)findViewById(R.id.btn_update);btnAdd.setOnClickListener(this); //Button控件設(shè)置監(jiān)聽btnQuery.setOnClickListener(this);btnUpdate.setOnClickListener(this);findViewById(R.id.traceroute_rootview).setOnClickListener(this);tvShow.setMovementMethod(ScrollingMovementMethod.getInstance()); //設(shè)置文本滾動 } public void onClick(View v){SQLiteDatabase db;switch (v.getId()){ case R.id.traceroute_rootview:InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(v.getWindowToken(),0);break; case R.id.btn_add: //添加聯(lián)系人Intent intent=new Intent(MainActivity.this,nextActivity.class);startActivity(intent);break; case R.id.btn_query: //查詢聯(lián)系人db = myHelper.getReadableDatabase();Cursor cursor = db.rawQuery('select name,phone from person',null);if (cursor.getCount() == 0){ tvShow.setText(''); Toast.makeText(this,'當前無聯(lián)系人',Toast.LENGTH_SHORT).show();}else { cursor.moveToFirst(); tvShow.setText('Name:' + cursor.getString(0) + ' ; Tel:' + cursor.getString(1)); while (cursor.moveToNext()){tvShow.append('n' + 'Name:' + cursor.getString(0) + ' ; Tel:' + cursor.getString(1)); }}cursor.close();db.close();break; case R.id.btn_update: //修改聯(lián)系人Intent intent1=new Intent(MainActivity.this,xiugaiActivity.class);startActivity(intent1);break;} }}

nextActivity

package com.example.test; import androidx.appcompat.app.AppCompatActivity;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.database.sqlite.SQLiteDatabase;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.Button;import android.widget.EditText;import android.widget.Toast; public class nextActivity extends AppCompatActivity implements View.OnClickListener { MyHelper myHelper; private EditText etName; private EditText etPhone; private Button btnAdd; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.next);myHelper = new MyHelper(this);init(); } private void init(){etName = (EditText)findViewById(R.id.et_name);etPhone = (EditText)findViewById(R.id.et_phone);btnAdd = (Button)findViewById(R.id.btn_add);btnAdd.setOnClickListener(this); //Button控件設(shè)置監(jiān)聽findViewById(R.id.traceroute_rootview).setOnClickListener(this); } public void onClick(View v){String name;String phone;SQLiteDatabase db;switch (v.getId()) { case R.id.traceroute_rootview:InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(v.getWindowToken(), 0);break; case R.id.btn_add: //添加聯(lián)系人name = etName.getText().toString().trim();phone = etPhone.getText().toString().trim();db = myHelper.getWritableDatabase();if (name.equals('') || phone.equals('')) { //聯(lián)系人信息不能為空 Toast.makeText(this, '聯(lián)系人信息添加失敗', Toast.LENGTH_SHORT).show();} else { db.execSQL('insert into person (name,phone) values(?,?)', new Object[]{name, phone}); Toast.makeText(this, '聯(lián)系人信息添加成功', Toast.LENGTH_SHORT).show();}db.close();Intent intent=new Intent(nextActivity.this,MainActivity.class);startActivity(intent);break;} }}

xiugaiActivity

package com.example.test; import androidx.appcompat.app.AppCompatActivity;import android.content.Context;import android.os.Bundle;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.text.method.ScrollingMovementMethod;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;public class xiugaiActivity extends AppCompatActivity implements View.OnClickListener{ MyHelper myHelper; private EditText etName; private EditText etPhone; private TextView tvShow; private Button btnQuery; private Button btnUpdate; private Button btnDelete; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.xiugai);myHelper = new MyHelper(this);init(); } private void init(){etName = (EditText)findViewById(R.id.et_name);etPhone = (EditText)findViewById(R.id.et_phone);tvShow = (TextView)findViewById(R.id.tv_show);btnQuery = (Button)findViewById(R.id.btn_query);btnUpdate = (Button)findViewById(R.id.btn_update);btnDelete = (Button)findViewById(R.id.btn_delete);btnQuery.setOnClickListener(this);btnUpdate.setOnClickListener(this);btnDelete.setOnClickListener(this);findViewById(R.id.traceroute_rootview).setOnClickListener(this);tvShow.setMovementMethod(ScrollingMovementMethod.getInstance()); //設(shè)置文本滾動 } public void onClick(View v){String name;String phone;SQLiteDatabase db;switch (v.getId()){ case R.id.traceroute_rootview:InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(v.getWindowToken(),0);break; case R.id.btn_query: //查詢聯(lián)系人db = myHelper.getReadableDatabase();Cursor cursor = db.rawQuery('select name,phone from person',null);if (cursor.getCount() == 0){ tvShow.setText(''); Toast.makeText(this,'當前無聯(lián)系人',Toast.LENGTH_SHORT).show();}else { cursor.moveToFirst(); tvShow.setText('Name:' + cursor.getString(0) + ' ; Tel:' + cursor.getString(1)); while (cursor.moveToNext()){tvShow.append('n' + 'Name:' + cursor.getString(0) + ' ; Tel:' + cursor.getString(1)); }}cursor.close();db.close();break; case R.id.btn_update: //修改聯(lián)系人db = myHelper.getWritableDatabase();name = etName.getText().toString().trim();phone = etPhone.getText().toString().trim();if (name.equals('') || phone.equals('')){ //聯(lián)系人信息不能為空 Toast.makeText(this,'不存在該聯(lián)系人',Toast.LENGTH_SHORT).show();}else { db.execSQL('update person set name=?,phone=? where name=?', new Object[]{name, phone, name}); Toast.makeText(this,'聯(lián)系人信息修改成功',Toast.LENGTH_SHORT).show();}db.close();break; case R.id.btn_delete: //刪除聯(lián)系人db = myHelper.getWritableDatabase();name = etName.getText().toString().trim();phone = etPhone.getText().toString().trim();if (name.equals('') || phone.equals('')){ //聯(lián)系人信息不能為空 Toast.makeText(this,'不存在該聯(lián)系人',Toast.LENGTH_SHORT).show();}else { db.execSQL('delete from person where name=? and phone=?', new Object[]{name, phone}); Toast.makeText(this,'聯(lián)系人信息刪除成功',Toast.LENGTH_SHORT).show();}db.close();break;} }}

MyHelper

package com.example.test;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;public class MyHelper extends SQLiteOpenHelper{ public MyHelper(Context context){super(context, 'alan.db', null ,2); } @Override public void onCreate(SQLiteDatabase db){db.execSQL('create table person(id integer primary key autoincrement,name varchar(20),phone varchar(20) unique)'); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){ }}

activity_main.xml

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:orientation='vertical' android:layout_width='match_parent' android:layout_height='match_parent' android: android:background='@color/white' android:clickable='true' android:gravity='center_horizontal' tools:context='.MainActivity'><TextView android:layout_width='match_parent' android:layout_height='wrap_content' android:text='通 訊 錄' android:textSize='30dp' android:textStyle='italic' android:gravity='center' android:textColor='@color/black'></TextView><Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:background='@drawable/shape' android:text=' 添加聯(lián)系人' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/><Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:background='@drawable/shape' android:text='查看聯(lián)系人' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/><Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:background='@drawable/shape' android:text=' 修改聯(lián)系人' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/> <TextViewandroid: android:layout_width='match_parent'android:layout_height='180dp'android:scrollbars='vertical'android:layout_below='@+id/lineFour'android:layout_marginTop='20dp'android:layout_marginLeft='20dp'android:layout_marginRight='18dp'android:textColor='#c2c8ec'android:textSize='24dp'/></LinearLayout>

next.xml

<?xml version='1.0' encoding='utf-8'?><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' android: android:background='@color/white' android:clickable='true' android:orientation='vertical' android:gravity='center_horizontal' tools:context='.nextActivity'> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:layout_below='@+id/lineOne'android:layout_marginTop='20dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'><TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='姓 名 : ' android:textSize='18dp' android:textStyle='bold'/><EditText android: android:layout_width='match_parent' android:layout_height='wrap_content' android:hint='請輸入姓名' android:textSize='16dp' android:maxLines='1' android:singleLine='true' android:maxLength='14'/> </LinearLayout> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:layout_below='@+id/lineTwo'android:layout_marginTop='10dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'> <TextViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:text='電 話 : 'android:textSize='18dp'android:textStyle='bold'/> <EditTextandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:hint='請輸入手機號碼'android:textSize='16dp'android:maxLines='1'android:singleLine='true'android:maxLength='11'/> </LinearLayout> <LinearLayoutandroid:layout_width='match_parent'android:layout_height='wrap_content'android: android:layout_below='@+id/lineTree'android:layout_marginTop='30dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'android:orientation='horizontal'> <Buttonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:background='@drawable/shape'android:layout_weight='1'android:text=' 確 定 'android:textSize='16dp'android:textColor='#c2c8ec'android:textStyle='bold'/> </LinearLayout></RelativeLayout>xiugai.xml<?xml version='1.0' encoding='utf-8'?><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' android: android:background='@color/white' android:clickable='true' android:orientation='vertical' android:gravity='center_horizontal' tools:context='.xiugaiActivity'> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:layout_below='@+id/lineOne'android:layout_marginTop='20dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'><TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='姓 名 : ' android:textSize='18dp' android:textStyle='bold'/><EditText android: android:layout_width='match_parent' android:layout_height='wrap_content' android:hint=' 請輸入姓名' android:textSize='16dp' android:maxLines='1' android:singleLine='true' android:maxLength='14'/> </LinearLayout> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:layout_below='@+id/lineTwo'android:layout_marginTop='10dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'><TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='電 話 : ' android:textSize='18dp' android:textStyle='bold'/><EditText android: android:layout_width='match_parent' android:layout_height='wrap_content' android:hint=' 請輸入手機號碼' android:textSize='16dp' android:maxLines='1' android:singleLine='true' android:maxLength='11'/> </LinearLayout> <LinearLayoutandroid:layout_width='match_parent'android:layout_height='wrap_content'android: android:layout_below='@+id/lineTree'android:layout_marginTop='30dp'android:layout_marginLeft='18dp'android:layout_marginRight='18dp'android:orientation='horizontal'><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:background='@drawable/shape' android:layout_weight='1' android:layout_marginLeft='4dp' android:text='查看聯(lián)系人' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:background='@drawable/shape' android:layout_weight='1' android:layout_marginLeft='4dp' android:text=' 修 改 ' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:background='@drawable/shape' android:layout_weight='1' android:layout_marginLeft='4dp' android:text=' 刪 除 ' android:textSize='16dp' android:textColor='#c2c8ec' android:textStyle='bold'/> </LinearLayout> <TextViewandroid: android:layout_width='match_parent'android:layout_height='180dp'android:scrollbars='vertical'android:layout_below='@+id/lineFour'android:layout_marginTop='20dp'android:layout_marginLeft='20dp'android:layout_marginRight='18dp'android:textColor='#c2c8ec'android:textSize='24dp'/></RelativeLayout>

Mainfest

<?xml version='1.0' encoding='utf-8'?><manifest xmlns:android='http://schemas.android.com/apk/res/android' package='com.example.test'> <applicationandroid:allowBackup='true'android:icon='@mipmap/ic_launcher'android:label='@string/app_name'android:roundIcon='@mipmap/ic_launcher_round'android:supportsRtl='true'android:theme='@style/Theme.Test'><activity android:name='.MainActivity'> <intent-filter><action android:name='android.intent.action.MAIN' /> <category android:name='android.intent.category.LAUNCHER' /> </intent-filter></activity><activity android:name='.nextActivity'></activity><activity android:name='.xiugaiActivity'></activity> </application> </manifest>

初學android,程序還存在許多bug,大家多提修改建議。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
88xx成人免费观看视频库| 亚洲激情黄色| 日韩在线网址| 中文字幕成人| 99精品99| 亚洲欧美久久| 首页亚洲欧美制服丝腿| 三级欧美在线一区| 日韩欧美三区| 国产精品美女午夜爽爽| 国产精品xvideos88| 久久精品国产在热久久| 国产成人精品一区二区三区免费 | 亚洲综合色婷婷在线观看| 免费人成精品欧美精品| 亚洲精品系列| 国产日韩精品视频一区二区三区| 国产亚洲久久| 国产精品99一区二区三| 日韩精品午夜| 亚洲欧美高清| 欧美啪啪一区| 福利一区在线| 亚洲精品电影| 亚洲aa在线| 国产日韩亚洲欧美精品| 精品美女久久| 国产一区欧美| 亚洲精品韩国| 国产精品巨作av| 日韩高清中文字幕一区二区| 99国产精品| 亚洲欧美专区| 麻豆成人91精品二区三区| 久久久蜜桃一区二区人| 蜜臀av性久久久久蜜臀aⅴ流畅| 日韩高清在线观看一区二区| 久久97视频| 亚洲午夜一级| 777久久精品| 久久男人av| 欧美日韩国产高清电影| 青青草精品视频| 欧美成a人国产精品高清乱码在线观看片在线观看久 | 亚洲美女91| 久久精品资源| 亚洲视频www| 免费日韩一区二区三区| 激情五月综合| 久久99久久人婷婷精品综合| 性欧美xxxx免费岛国不卡电影| 蜜臀久久久久久久| 国产suv精品一区| 丝袜国产日韩另类美女| 麻豆一区二区三| av不卡在线看| 精品国产一区二区三区性色av| 中文在线一区| 色偷偷偷在线视频播放| 午夜亚洲福利| 色婷婷精品视频| 久久国际精品| 国产美女精品| 日韩欧美中文字幕一区二区三区 | 亚洲人成网77777色在线播放| 狠狠久久伊人| 亚洲久久在线| 国产精品99免费看| 精品资源在线| 日韩欧美中文字幕电影| 91成人超碰| 日韩成人精品一区| 日韩精品免费视频人成| 精品中文一区| 国产66精品| 国产区精品区| 亚洲精品va| 激情黄产视频在线免费观看| 日本一区二区三区中文字幕| 久久久久久久久99精品大| 麻豆国产精品一区二区三区| 中文字幕免费精品| 蜜桃视频欧美| 中文在线а√天堂| 国产精品调教| 亚洲精品欧洲| 欧美日韩激情| 日韩久久精品| 精品国产一区二区三区av片| 日本在线不卡视频一二三区| 精品1区2区3区4区| 国产一区二区三区黄网站| 日韩av黄色在线| 蜜桃视频在线观看一区二区| 亚洲国产不卡| 免费污视频在线一区| 久久精品国产福利| 国产欧美在线| 日韩av三区| 日产欧产美韩系列久久99| 欧美一级精品| 三级小说欧洲区亚洲区| 国产成人1区| 久久97久久97精品免视看秋霞| 欧美一级全黄| 日本欧美一区二区| 亚洲免费在线| 国产亚洲激情| 亚洲黄页一区| 亚洲精品网址| 午夜精品影院| 欧美精选一区二区三区| 亚洲夜间福利| 精品一区在线| 亚洲精品在线观看91| 亚洲午夜视频| 欧美在线资源| 亚洲欧美日韩综合国产aⅴ| aⅴ色国产欧美| 视频一区视频二区在线观看| 免费精品视频最新在线| 日韩制服丝袜先锋影音| 黄色精品网站| 国产一区白浆| 视频一区在线播放| 亚洲欧美久久精品| 日韩欧美精品一区二区综合视频| 视频一区日韩精品| 91综合久久爱com| 国产毛片精品久久| 国产精品久久国产愉拍| 国产精品久久久久av蜜臀| 免费亚洲一区| 在线看片国产福利你懂的| 日本在线精品| 黄色日韩在线| 视频在线在亚洲| 日韩欧美中文字幕在线视频| 国产日韩亚洲欧美精品| 欧美激情99| 91日韩免费| 香蕉久久99| 国产精品丝袜xxxxxxx| 亚洲精品福利| 欧美精品成人| 精精国产xxxx视频在线播放| 美女网站一区| 日韩中文字幕| 国产精品毛片aⅴ一区二区三区| 精品国产亚洲一区二区三区大结局| 国产一区精品福利| 高清av不卡| 影音先锋国产精品| 日本91福利区| 欧美xxxx中国| 欧美特黄a级高清免费大片a级| 蜜臀精品久久久久久蜜臀| 国产另类在线| 欧美freesex黑人又粗又大| 免播放器亚洲| 国产欧美69| 99精品视频在线| 四虎成人精品一区二区免费网站| 久久字幕精品一区| 亚洲高清二区| 日本不卡中文字幕| 精品国产不卡一区二区| 91精品婷婷色在线观看| 蜜臀av国产精品久久久久| 久久伊人亚洲| 日韩一区二区免费看| 国产精品久久免费视频| 日韩精品一区二区三区免费观影| 丝袜a∨在线一区二区三区不卡| 国产欧美二区| 极品日韩av| 国产精品毛片aⅴ一区二区三区| 久久久久国产精品一区二区| 亚洲免费毛片| 国产v日韩v欧美v| 亚洲欧美日韩一区在线观看| 国产精品亚洲人成在99www| 久久久久91| 欧美另类中文字幕 | 亚洲免费在线| 国产成人精选| 亚洲免费福利一区| 欧美aa在线观看| 欧美中文一区| 欧美va天堂在线| 麻豆极品一区二区三区| 麻豆亚洲精品| 日韩欧美午夜| 欧美精品福利| 国产高清一区| 久久av免费| 日韩精品一级中文字幕精品视频免费观看| 蜜桃久久久久| 日韩精品亚洲专区| 亚洲国产一区二区在线观看|