基於Sqlite數據開發的安卓簡易通訊錄

基於Sqlite數據開發的安卓簡易通訊錄

開發環境

Android Studio集成開發環境,下載,安裝教程及無法聯網更新問題,請轉至:Android Studio下載安裝教程

進入主題
效果圖
在這裏插入圖片描述

目錄結構
其中user_info.javaacticity_main.xml作爲附加調試時使用的,項目沒有使用。
在這裏插入圖片描述
廢話不多說,直接上代碼

主頁面
MainActivity.java

package com.example.administrator.pc;
import android.content.Intent;
import android.widget.Button;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import androidx.appcompat.app.AppCompatActivity;



public class MainActivity extends AppCompatActivity
{
	public Button button_add_info;
	public Button button_query;
	public Button button_delete;
	public Button button_addition;
	public SQLiteDatabase call_db;
	public DBHelper db;

	//定義Button,ListView,list數據集合,simpleAdapter適配器
	private Button create,query;
	private ListView listview = null;
	private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	private SimpleAdapter simpleAdapter = null;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		query=(Button)findViewById(R.id.query_phone);
		create=(Button)findViewById(R.id.add_phone_name);

	}


	public void onclick0(View view){

		Intent intent=new Intent(MainActivity.this,addrelation.class);
		startActivity(intent);
	}
	public void onclick1(View view){

		Intent inte1=new Intent(MainActivity.this,query_activity.class);
		startActivity(inte1);
	}
	public void onclick2(View view){
		Intent int_del=new Intent(MainActivity.this,delete_activity.class);
		startActivity(int_del);
		//delete_table();
	}
	public void onclick4(View view)
	{
		Intent inte_up=new Intent(MainActivity.this,update_activity.class);
		startActivity(inte_up);
	}
	public void delete_table(){
		db.execsql_w();
		Toast.makeText(MainActivity.this,"刪除成功",Toast.LENGTH_LONG).show();
	}
}

添加聯繫人
addrelation.java

package com.example.administrator.pc;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.widget.*;
import android.os.Bundle;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;


public class addrelation extends AppCompatActivity
{
   public EditText username;
   public EditText userphone;
   public Spinner userattribute;

   private static int ch=0;
   private Spinner spinner1;

   DBHelper db=new DBHelper(this,null,null,0);
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
	  // TODO: Implement this method
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.addrelation);
	  spinner1=(Spinner) findViewById(R.id.spinner1);
	  initSpinner1();
	  init();
	  Button save=(Button)findViewById(R.id.save);
	  //save.setOnClickListener(new MySaveBtnListener());
   }
   private void init(){
	  username=(EditText)findViewById(R.id.addName);
	  userphone=(EditText)findViewById(R.id.addTel);
	  userattribute=(Spinner)findViewById(R.id.spinner1);
   }
 
  public void insert_db(int ch){

	 String name=username.getText().toString();
	 String phone=userphone.getText().toString();
	 String attribute=(String)spinner1.getSelectedItem();
	 if(ch==1){
		String sql="insert into Userinfo values(?,?,?,?)";
		db.execsql(sql, new Object[]{null,name,phone,attribute});
		Toast.makeText(addrelation.this,"保存成功",Toast.LENGTH_LONG).show();
	 }
	 else{
		return;
	 }
  }
   public void initSpinner1(){
	  String[] city=new String[]{"同事","家人","朋友","同學"};
	  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, city);
	  spinner1.setAdapter(adapter);
   }
   public void onclick_save(View view) //這個方法是彈出一個對話框
   {
	initEvent();
   }
   public void onclick_exit(View view)//退出按鈕響應
   {
	   finish();
   	}
   private void initEvent() {	//初始化事件,即:對話框的顯示
	  showDialog();
   }

   private void showDialog(){
	  String name=username.getText().toString();
	  String phone=userphone.getText().toString();
	  if(name.equals("")){
		 Toast.makeText(addrelation.this,"溫馨提示:請輸入聯繫人名稱", Toast.LENGTH_LONG).show();
	  }
	  else if(phone.equals("")){
		 Toast.makeText(addrelation.this,"溫馨提示:請輸入聯繫人號碼", Toast.LENGTH_LONG).show();
	  }
	  else{
	  AlertDialog.Builder builder=new AlertDialog.Builder(this);
	 // builder.setIcon(R.drawable..);
	  builder.setTitle("提示");
	  builder.setMessage("是否保存?");
	  builder.setPositiveButton("保存",
		 new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialogInterface, int i) {
			   ch=1;
			   insert_db(ch);
			   ch=0;
			}
		 });
		 builder.setNegativeButton("放棄",new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialogInterface,int i){
			   ch=0;
			   insert_db(ch);
		}
		 });
	  AlertDialog dialog=builder.create();
	  dialog.show();
	  }
   }
}

刪除聯繫人
delete_activity.java

package com.example.administrator.pc;

import android.os.Bundle;
import android.view.*;
import android.database.sqlite.SQLiteDatabase;
import android.widget.EditText;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;

import androidx.appcompat.app.AppCompatActivity;

public class delete_activity extends AppCompatActivity {
    private DBHelper db;
    private int VERSION=1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.delete_user);
    }
    public  void onclick0(View view)
    {
        finish();
    }
    public void onclick1(View view)
    {
        showDialog();
    }
    public void deleteById()
    {
        EditText dele_id=findViewById(R.id.del_id);
        EditText dele_name=findViewById(R.id.del_name);
        EditText dele_phone=findViewById(R.id.del_phone);
        EditText dele_attribute=findViewById(R.id.del_attribute);

        String id=dele_id.getText().toString();
        String name=dele_name.getText().toString();
        String phone=dele_phone.getText().toString();
        String attribute=dele_attribute.getText().toString();

        DBHelper helper=new DBHelper(getApplicationContext(),"contact_db",null,VERSION);
        SQLiteDatabase db=helper.getWritableDatabase();
        if(!id.equals("")||!name.equals("")||!phone.equals("")||!attribute.equals(""))
        {
                if (!id.equals(""))
                //if(id!=0)
                {
                    db.execSQL("Delete from Userinfo where id= ? ", new Object[]{id});
                }
                if (!name.equals(""))
                //if(id!=0)
                {
                    db.execSQL("Delete from Userinfo where username= ? ", new Object[]{name});
                }
                if (!phone.equals(""))
                //if(id!=0)
                {
                    db.execSQL("Delete from Userinfo where userPhone= ? ", new Object[]{phone});
                }
                if (!attribute.equals(""))
                //if(id!=0)
                {
                    db.execSQL("Delete from Userinfo where attribute= ? ", new Object[]{attribute});
                }
                Toast.makeText(getApplicationContext(), "記錄刪除成功", Toast.LENGTH_SHORT).show();
        }
        else{
                    Toast.makeText(getApplicationContext(),"溫馨提示:請輸入刪除項", Toast.LENGTH_LONG).show();
            }
        db.close();
    }
    private  void showDialog()
    {
        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        // builder.setIcon(R.drawable..);
        builder.setTitle("提示");
        builder.setMessage("是否刪除?");
        builder.setPositiveButton("刪除", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                deleteById();
            }
        });
        builder.setNegativeButton("放棄", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(),"溫馨提示:取消成功", Toast.LENGTH_LONG).show();
            }
        });
        AlertDialog dialog=builder.create();
        dialog.show();
    }

}

修改聯繫人信息
update_activity.java

package com.example.administrator.pc;
import android.os.*;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
import android.widget.*;
import android.view.*;

import androidx.appcompat.app.AppCompatActivity;

public class update_activity extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO: Implement this method
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update_user);
    }
    public void onclick0(View view)
    {
        finish();
    }
    public void onclick1(View view){
        updateById();
    }
    public void updateById(){

        EditText u_id=findViewById(R.id.user_id);
        EditText u_name=findViewById(R.id.user_name);
        EditText u_phone=findViewById(R.id.user_phone);
        EditText u_attribute=findViewById(R.id.user_attribute);

        String id=u_id.getText().toString();
        String name=u_name.getText().toString();
        String phone=u_phone.getText().toString();
        String attribute=u_attribute.getText().toString();

        DBHelper helper = new DBHelper(getApplicationContext(), "contact_db", null,1);
        SQLiteDatabase db=helper.getWritableDatabase();
        if(!id.equals(""))
        {
            if(!name.equals("")||!phone.equals("")||!attribute.equals(""))
            {
                if(!name.equals(""))
                {
                    db.execSQL("Update Userinfo set username=? where id= ? ",new Object[ ]{ name,id} );
                }
                if(!phone.equals(""))
                {
                    db.execSQL("Update Userinfo set userPhone=? where id= ? ",new Object[ ]{ phone,id} );
                }
                if(!attribute.equals(""))
                {
                    db.execSQL("Update Userinfo set attribute=? where id= ? ",new Object[ ]{attribute,id} );
                }
                Toast.makeText(getApplicationContext(), "修改成功", Toast.LENGTH_SHORT).show();
                db.close();
            }
            else{
                Toast.makeText(getApplicationContext(), "沒有修改的項", Toast.LENGTH_SHORT).show();
            }
        }
        if(id.equals(""))
        {
            Toast.makeText(getApplicationContext(), "請輸入ID", Toast.LENGTH_SHORT).show();
        }
    }
}

查詢聯繫人信息
query_activity.java

package com.example.administrator.pc;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;
import android.database.sqlite.SQLiteDatabase;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import androidx.appcompat.app.AppCompatActivity;

public class query_activity extends AppCompatActivity
{
   public ListView listview;
   public SimpleAdapter simpleAdapter;
   
   private DBHelper  db;
   private  Cursor mCursor;//遊標,查詢後返回的對象
   private int id;//當前遊標Cursor所在的字段值
   private Cursor mCursor_query;
   
   public List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
	  // TODO: Implement this method
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.result_info);
	  ListView listV=findViewById(R.id.list);  
	  //獲取查詢結果  
	  ArrayList<HashMap<String, Object>> listData=fillList();  
	  //獲取適配器  
	  SimpleAdapter adapter=fillAdapter(listData);  
	  //將適配器內容添加並且顯示
	  listV.setAdapter(adapter);
	  }

   public  ArrayList<HashMap<String, Object>> fillList(){
	  //生成動態數組,並且轉載數據    
	  ArrayList<HashMap<String, Object>> dataList = new ArrayList<HashMap<String, Object>>();    

	  DBHelper helper=new DBHelper(query_activity.this,"contact_db",null,1);
	  SQLiteDatabase db=helper.getReadableDatabase();  

	  try{  
		 Cursor cursor=helper.query("select * from Userinfo",null);   
		 cursor.moveToFirst();  
		 
		 if(cursor.moveToFirst()) {
			String appId=cursor.getString(cursor.getColumnIndex("id"));
			String appname = cursor.getString(cursor.getColumnIndex("username"));    
			String appphone = cursor.getString(cursor.getColumnIndex("userPhone"));   
			String appDescription = cursor.getString(cursor.getColumnIndex("attribute"));   

			HashMap<String, Object> map = new HashMap<String, Object>();    
			map.put("id_num",appId);
			map.put("name",appname);    
			map.put("phone", appphone);    
			map.put("other", appDescription);    
			dataList.add(map);    
		 }    
		 while(cursor.moveToNext()) {
			String appId=cursor.getString(cursor.getColumnIndex("id"));
			String appname = cursor.getString(cursor.getColumnIndex("username"));    
			String appphone = cursor.getString(cursor.getColumnIndex("userPhone"));   
			String appDescription = cursor.getString(cursor.getColumnIndex("attribute"));   

			HashMap<String, Object> map = new HashMap<String, Object>();    
			map.put("id_num",appId);
			map.put("name",appname);    
			map.put("phone", appphone);    
			map.put("other", appDescription);    
			dataList.add(map);    
		 }
	  }catch(Exception ex){  
		 ex.printStackTrace();  
	  }finally{  

		 if(db.isOpen()){  
			db.close();  
		 }  
	  }
	  return dataList;  
   }
   /** 
	* 填充數據,取得數據適配器. 
	* @param listData 
	* @return 
	*/  
   public SimpleAdapter fillAdapter(ArrayList<HashMap<String, Object>> listData){  
	  //生成適配器,數組===》ListItem    
	    // mCursor=db.searchAllData();
		// mCursor=mCursor_query;
	  if (mCursor != null && mCursor.getCount() >= 0)
	  {}
		 SimpleAdapter adapter = new SimpleAdapter(query_activity.this,  
												listData,//數據來源     
												R.layout.list,//ListItem的XML實現    
												//動態數組與ListItem對應的子項            
												new String[] {"id_num","name", "phone","other"},     
												//ListItem的XML文件裏面的四個個TextView ID
												new int[] {R.id.id_num,R.id.name,R.id.phone,R.id.other});
	  return adapter;  
	  }
 }

佈局

主頁面佈局
main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	android:orientation="vertical"
	android:background="@drawable/bg08">
	<TableLayout
	   android:layout_width="match_parent"
	   android:layout_height="match_parent"
	   android:orientation="vertical">
	<LinearLayout
	   android:paddingTop="82dp"
	   android:paddingLeft="57dp"
	   android:orientation="horizontal">
	<Button
	   android:onClick="onclick0"
	   android:background="@drawable/shapes"
	   android:textColor="#000000"
	   android:layout_margin="5dp"
	   android:layout_height="100dp"
	   android:layout_width="140dp"
	   android:id="@+id/add_phone_name"
	   android:text="添加聯繫人"
	   android:radius="18dp"/>
	<Button
	   android:onClick="onclick1"
	   android:background="@drawable/shapes"
	   android:textColor="#000000"
	   android:layout_margin="5dp"
	   android:layout_height="100dp"
	   android:layout_width="140dp"
	   android:id="@+id/query_phone"
	   android:text="查看聯繫人"
	   android:radius="18dp"/>
	</LinearLayout>
   <LinearLayout
	  android:paddingLeft="57dp"
	  android:orientation="horizontal">
	  <Button
		 android:onClick="onclick2"
		 android:background="@drawable/shapes"
		 android:textColor="#000000"
		 android:layout_margin="5dp"
		 android:layout_height="100dp"
		 android:layout_width="140dp"
		 android:id="@+id/del_phone_name"
		 android:text="刪除聯繫人"
		 android:radius="18dp"/>
	  <Button
		 android:background="@drawable/shapes"
		 android:textColor="#000000"
		 android:layout_height="100dp"
		 android:layout_width="140dp"
		 android:id="@+id/other_info"
		 android:text="聯繫人備註"
		 android:layout_margin="5dp"
		 android:radius="18dp"
		 />
   </LinearLayout>
	   <LinearLayout
		  android:paddingLeft="57dp"
		  android:orientation="horizontal">
		  <Button
              android:onClick="onclick4"
			 android:background="@drawable/shapes"
			 android:textColor="#000000"
			 android:layout_margin="5dp"
			 android:layout_height="100dp"
			 android:layout_width="140dp"
			 android:id="@+id/update_phone_name"
			 android:text="更改聯繫人"
			 android:radius="18dp"/>
		  <Button
			 android:background="@drawable/shapes"
			 android:textColor="#000000"
			 android:layout_height="100dp"
			 android:layout_width="140dp"
			 android:id="@+id/other_function"
			 android:text="附加功能"
			 android:layout_margin="5dp"
			 android:radius="18dp"
		  />
	   </LinearLayout>
	   <LinearLayout
		  android:paddingLeft="57dp"
		  android:orientation="horizontal">
		  <Button
			 android:background="@drawable/shapes"
			 android:textColor="#000000"
			 android:layout_margin="5dp"
			 android:layout_height="100dp"
			 android:layout_width="140dp"
			 android:id="@+id/my_log"
			 android:text="智能備忘錄"
			 android:radius="18dp"/>
		  <Button
			 android:background="@drawable/shapes"
			 android:textColor="#000000"
			 android:layout_height="100dp"
			 android:layout_width="140dp"
			 android:id="@+id/kuaidi_query"
			 android:text="快遞查詢"
			 android:layout_margin="5dp"
			 android:radius="18dp"
		  />
	   </LinearLayout>
	</TableLayout>
   
</LinearLayout>

添加
addrelation.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
	android:background="@drawable/bg_pic">
	
	<LinearLayout
	   >
   <Button
	  android:background="#00aaff"
	  android:layout_width="wrap_content"
	  android:layout_height="wrap_content"
	  android:text="姓名" 
	  android:textColor="#ffffff"/>
   <EditText
	  android:id="@+id/addName"
	  android:layout_width="match_parent"
	  android:layout_height="wrap_content" />
	</LinearLayout>
   <LinearLayout
	  android:paddingTop="5dp">
   <Button
	  android:textColor="#ffffff"
	  android:background="#00aaff"
	  android:layout_width="wrap_content"
	  android:layout_height="wrap_content"
	  android:text="電話" />
   <EditText
	  android:id="@+id/addTel"
	  android:layout_width="match_parent"
	  android:layout_height="wrap_content" />
   </LinearLayout>
   <LinearLayout
	  android:paddingTop="10dp">
   <Button
	  android:background="#00aaff"
	  android:layout_width="wrap_content"
	  android:layout_height="wrap_content"
	  android:textColor="#ffffff"
	  android:text="所屬組" />
   <Spinner
	  android:id="@+id/spinner1"
	  android:layout_width="match_parent"
	  android:layout_height="match_parent"
	  />
   </LinearLayout>
   <LinearLayout
	  android:paddingTop="10dp"
	  android:layout_width="match_parent"
	  android:layout_height="match_parent"
	  android:orientation="vertical">
   <Button
	  android:onClick="onclick_save"
	  android:id="@+id/save"
	  android:layout_width="match_parent"
	  android:layout_height="wrap_content"
	  android:background="#e47833"
	  android:text="  保存    " />
   <Button
	  android:id="@+id/exit"
	  android:paddingTop="5dp"
	  android:layout_width="match_parent"
	  android:layout_height="wrap_content"
	  android:onClick="onclick_exit"
	  android:text="  返回   " />
   </LinearLayout>

    
</TableLayout>

修改
update_user.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/bg_pic">

    <LinearLayout
        android:paddingTop="5dp"
        android:paddingLeft="5dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <Button
            android:background="#00aaff"
            android:text="聯繫人的ID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/user_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    <LinearLayout
        android:paddingLeft="5dp"
        android:paddingTop="5dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <Button
            android:background="#00aaff"
            android:text="姓名修改爲"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/user_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    <LinearLayout
        android:paddingLeft="5dp"
        android:paddingTop="5dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <Button
            android:background="#00aaff"
            android:text="號碼修改爲"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/user_phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    <LinearLayout
        android:paddingLeft="5dp"
        android:paddingTop="5dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <Button
            android:background="#00aaff"
            android:text="組類修改爲"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/user_attribute"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>
    <LinearLayout
        android:paddingTop="50dp"
        android:paddingLeft="100dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <Button
            android:onClick="onclick0"
            android:text="返回"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:onClick="onclick1"
            android:id="@+id/delete_bu"
            android:text="修改"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <TextView
        android:gravity="center"
        android:paddingTop="100dp"
        android:paddingLeft="100dp"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="提醒:未做修改值以默認值存在"/>
</LinearLayout>

刪除
delete_user.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg02">

    <LinearLayout
        android:paddingTop="5dp"
        android:paddingLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <Button
        android:background="#00aaff"
        android:text="By_ID"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>
        <EditText
            android:id="@+id/del_id"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <LinearLayout
        android:paddingTop="5dp"
        android:paddingLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:background="#00aaff"
            android:text="By_姓名"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>
        <EditText
            android:id="@+id/del_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <LinearLayout
        android:paddingTop="5dp"
        android:paddingLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:background="#00aaff"
            android:text="By_電話"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>
        <EditText
            android:id="@+id/del_phone"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <LinearLayout
        android:paddingTop="5dp"
        android:paddingLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:background="#00aaff"
            android:text="By_類別"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>
        <EditText
            android:id="@+id/del_attribute"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <LinearLayout
        android:paddingTop="50dp"
        android:paddingLeft="100dp"
        android:paddingRight="100dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <Button
            android:onClick="onclick0"
            android:text="返回"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
        <Button
            android:onClick="onclick1"
            android:id="@+id/delete_id"
            android:text="刪除"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
     </LinearLayout>
    <TextView
        android:gravity="center"
        android:paddingTop="100dp"
        android:paddingLeft="100dp"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="提醒:以類別刪除的聯繫人將以批量刪除"/>
</LinearLayout>

查詢
result_info.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
	
   <LinearLayout
	  android:background="#999999"
	  android:orientation="horizontal"
	  android:layout_width="fill_parent"
	  android:layout_height="wrap_content">

	  <TextView
		 android:gravity="center"
		 android:id="@+id/ID_num"
		 android:layout_width="100dp"
		 android:layout_height="50dp"
		 android:text="序號"
		 android:textSize="20sp"
	  />
	  
	  <TextView
		 android:gravity="center"
		 android:id="@+id/name"
		 android:layout_width="100dp"
		 android:layout_height="50dp"
		 android:text="姓名"
		 android:textSize="20sp"
	  />

	  <TextView
		 android:gravity="center"
		 android:id="@+id/phone"
		 android:layout_width="100dp"
		 android:layout_height="50dp"
		 android:text="電話"
		 android:textSize="20sp"
	  />

	  <TextView
		 android:gravity="center"
		 android:id="@+id/attribute"
		 android:layout_width="fill_parent"
		 android:layout_height="50dp"
		 android:text="類別"
		 android:textSize="20sp"
	  />

   </LinearLayout>
   <!-- ListView控件 -->
   <ListView  
	  android:background="#FFFFFF"
	  android:layout_width="fill_parent" 
	  android:layout_height="fill_parent" 
	  android:id="@+id/list">
   </ListView>
    
</LinearLayout>

列表
list.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
	
	<LinearLayout
	   android:orientation="horizontal">
   <TextView
	  android:gravity="center"
	  android:id="@+id/id_num"
	  android:layout_width="100dp"
	  android:layout_height="40dp"
	  android:text="ID"
		  />
   <TextView
	  android:gravity="center"
	  android:id="@+id/name"
	  android:layout_width="100dp"
	  android:layout_height="40dp"
	  android:text="名字" 
	  
	  />
   <TextView
	  android:gravity="center"
	  android:id="@+id/phone"
	  android:layout_width="100dp"
	  android:layout_height="40dp"
	  android:text="號碼"
	  />

   <TextView
	  android:gravity="center"
	  android:id="@+id/other"
	  android:layout_width="fill_parent"
	  android:layout_height="40dp"
	  android:text="屬性"
	  
	  />
    
	</LinearLayout>
   </TableLayout>

按鈕形狀
btn_all_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

   <corners
	  android:bottomLeftRadius="20dp"
	  android:bottomRightRadius="20dp"
	  android:topLeftRadius="20dp"
	  android:topRightRadius="20dp" />
</shape>

配置activity
AndroidMainifest.xml

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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".addrelation"
            android:label="聯繫人">
        </activity>
        <activity android:name=".query_activity"
            android:label="查詢結果">
        </activity>
        <activity android:name=".delete_activity"
            android:label="刪除聯繫人">
        </activity>
        <activity android:name=".update_activity"
            android:label="修改聯繫人">
        </activity>
    </application>

</manifest>

功能簡介

實現對聯繫人簡單的增刪改查操作
功能簡單,界面醜陋,僅供參考

項目源碼
網盤地址鏈接:https://pan.baidu.com/s/1sY1SnFjrna0uYlKjzHfezQ

提取碼:74gd

版權聲明

未經的作者允許,嚴禁轉載任何內容,以上內容均由作者本人提供以及製作,不得用於進行任何營利性用途
更多關於作者教程:地址:152.136.70.33

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章