设为首页 加入收藏

TOP

Android 个人手机通讯录开发(一)
2019-08-30 01:01:10 】 浏览:99
Tags:Android 个人 手机 通讯录 开发

Android 个人手机通讯录开发

  数据存储:SQLite 数据库

  开发工具:Android Studio

Phone Module 简介

界面展示

              

 

文件结构简单分析

 

个人手机通讯录代码实现

清单文件 (AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.alan.directory" >

    <application android:allowBackup="true" android:icon="@drawable/icon_phone" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

MainActivity.java (主文件)

/** * Created by Alan J on 13/2/2019. */

package com.example.alan.directory; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.view.View; 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 EditText etName; private EditText etPhone; private TextView tvShow; private Button btnAdd; private Button btnQuery; private Button btnUpdate; private Button btnDelete; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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); btnAdd = (Button)findViewById(R.id.btn_add); btnQuery = (Button)findViewById(R.id.btn_query); btnUpdate = (Button)findViewById(R.id.btn_update); btnDelete = (Button)findViewById(R.id.btn_delete); btnAdd.setOnClickListener(this);          //Button控件设置监听
        btnQuery.setOnClickListener(this); btnUpdate.setOnClickListener(this); btnDelete.setOnClickListener(this); tvShow.setMovementMethod(ScrollingMovementMethod.getInstance()); //设置文本滚动
 } @Override public void onClick(View v){ String name; String phone; SQLiteDatabase db; switch (v.getId()){ case R.id.btn_add:       //添加联系人
                name = etName.getText().toString().trim(); phone = etPhone.getText().toString().trim(); db = myHelper.getWritableDatabase(); if (name.equals("") || phone.equals("")){    //联系人信息不能为空
                    Toast.makeText(this,"联系人信息添加失败",Toast.LENGTH_SHORT).show(); } else { db.execSQL("insert into person (name,phone) values(?,?)", new Object[]{name, phone}); Toast.makeText(this,"联系人信息添加成功",Toast.LENGTH_SHORT).show(); } db.close(); break; case R.id.btn_query:    //查询联系人
                db = myHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("select name,ph
首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇环信easeui集成:坑总结2018(二) 下一篇C:\Program Files\Java\jdk1.7.0_..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目