Android通讯录代码

package com.db;
t.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class DBHelper extends SQLiteOpenHelper {
   
    private static final String DB_NAME = "contact_db";
    // 定义初始版本号为1
    private static final int VERSION = 1;
    // 单例模式
    private static DBHelper dbHelper = null;
    private SQLiteDatabase sqlDb;
    // 构造函数
    public DBHelper(Context context, String name, CursorFactory factory,
            int version) {
        super(context, DB_NAME, factory, VERSION);
    }
    // 重写OnCreate方法,在第一次执行时会自动创建数据库
    @Override
    public void onCreate(SQLiteDatabase db) {
       
c型卡环        String sql="create table UserContact(_id integer primary key autoincrement,img_id integer,name text not null,mobilePhone text,homePhone text,officePhone text,company text,position text,address text,remark text,time text,weekey integer)";
        // 执行sql命令
        db.execSQL(sql);
    }
    // 提供更新数据库的方法
mp3制作    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = "drop table if exists UserContact ";
        db.execSQL(sql);
        // 重新执行
        Create(db);
    }
    public void execsql(String sql,Object[] nums){
        SQLiteDatabase WritableDatabase();
        db.execSQL(sql, nums);
    }
   
    public Cursor query(String sql,String[] nums){
        SQLiteDatabase ReadableDatabase();
        Cursor c=db.rawQuery(sql, nums);
        return c;
    }
}
st;
SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;扁蓿豆
import java.util.Map;
import com.db.DBHelper;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
t.DialogInterface;
t.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
汽车投影import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
led节能灯制作import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
public class AddUser extends Activity {
    // 按钮控件
    private Button save_btn;
    private Button cancel_btn;
    private DBHelper db;
    private int imgid=0;
    private  ImageView imageview;
    private Gallery gallery;
    // 依次获取所有控件
    private EditText txt_name,txt_mobilePhone,txt_officePhone,txt_homePhone,txt_position,txt_company,txt_address,txt_remark;
    private ImageButton img_btn;
   
    private int[] images = { R.drawable.icon, R.drawable.a1,
            R.drawable.a2, R.drawable.a3, R.drawable.a4,
            R.drawable.a5, R.drawable.a6, R.drawable.a7,
            R.drawable.a8, R.drawable.a9, R.drawable.image10 };
    private int contact_id=0;
    private int ImgId = 0,text=0;
    protected void onCreate(Bundle savedInstanceState) {
        Create(savedInstanceState);
        setContentView(R.layout.add_contact);
        init();
        db=new DBHelper(this,null,null,0);
        // 加载所有控件
        img_btn=(ImageButton)findViewById(R.id.btn_img);
        save_btn=(Button)findViewById(R.id.btn_save);
        img_btn.setOnClickListener(new MyImageBtnListener());
        save_btn.setOnClickListener(new MySaveBtnListener());
        contact_id = Intent().getIntExtra("id", 0);
        initContactInfo(contact_id);
    }
   
   
    private void init(){
        txt_name=(EditText)findViewById(_name);
        txt_mobilePhone=(EditText)findViewById(_mobilePhone);
        txt_officePhone=(EditText)findViewById(_officePhone);
        txt_homePhone=(EditText)findViewById(_homePhone);
        txt_position=(EditText)findViewById(_position);
94crw        txt_company=(EditText)findViewById(_company);
        txt_address=(EditText)findViewById(_address);
        txt_remark=(EditText)findViewById(_remark);
    }
    // 图片按钮事件
    private class MyImageBtnListener implements OnClickListener {
        public void onClick(View v) {
            View vv=getLayoutInflater().inflate(R.layout.face_dialog, null);
            gallery=(Gallery) vv.findViewById(R.id.face_dialog_gallery);
            imageview=(ImageView) vv.findViewById(R.id.face_dialog_img);
            gallery.setAdapter(new imageAdapter());
            gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int position, long arg3) {
                imgid=position;
                ImgId=position;
                    imageview.setImageResource(images[position%images.length]);
                   
                }
                public void onNothingSelected(AdapterView<?> arg0) {

本文发布于:2024-09-22 19:31:49,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/167149.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:执行   数据库   控件   按钮   方法
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议