注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

学无止境

一点积累,与大家分享

 
 
 

日志

 
 

android 数据库 SQLiteOpenHelper和ContentProvider学习笔记---添加修改删除数据之联系人(二)  

2011-07-19 14:09:59|  分类: Android开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1.结构化分

      1)主界面:用来显示数据库列表,并响应menu菜单

               本程序为GContact.java,其主布局文件为contact_list.xml,其ListView的id必须声明为android:id="@+id/android:list",这样系统才可  

               以在ListActivity里引用的到

      2 ) SQLiteOpenHelper类,该类里定义数据库名字:DATABASE_NAME = "bbbcontact.db"   并创建数据库表  表名:contactstable

            每个数据库表至少有一个字段_id。

      3)ContentProvider,其提供了数据库的增删该查方法,在此声明uri

      4)添加数据到数据库,AddContact.java,此界面完成添加数据和修改数据功能。

 

2.结构关系

     1)ContentProvider中用到SQLiteOpenHelper,在ContentProvider中的onCreate里创建DBHelper:

                        dbHelper = new DBHelper(getContext());

            通过 SQLiteDatabase db = dbHelper.getReadableDatabase();

                     SQLiteDatabase db = dbHelper.getWritableDatabase();    对数据库进行操作

     2)当程序界面需要对数据库进行更改时,不需要操作ContentProvider,而是操作getContentResolver,通过该接口即可访问    

             ContentProvider提供的数据

     3)在ContentProvider中定义URI:  public static final Uri CONTENT_URI = Uri.parse("content://"+AUTHORITY+"/contacts");

            其中“content://"为固定部分,AUTHORITY为权限声明,在manifext.xml文件中进行权限声明:

            <provider android:name="ContactProvider" android:authorities="com.bbb.contact"/>

            public static final String AUTHORITY = "com.bbb.contact";

           两字符串保持一致即可。

           当检索到数据库中的一组数据时,其uri后增加字段ID,无ID返回全部数据。

     4)由于添加和修改数据都要进入到AddContact.java中,故在跳转之前GContact.java中增加字段

            intent.setAction(AddContact.EDIT_TABLE_ACTION)表示为修改

            并在AddContact.java中进行判断,action = getIntent().getAction()           EDIT_TABLE_ACTION.equals(action)

            即可分辨是跳转到修改还是增加功能。

3.程序截图

    

 

TabContact.java

  1. import android.app.TabActivity;  
  2. import android.content.Intent;  
  3. import android.os.Bundle;  
  4. import android.view.LayoutInflater;  
  5. import android.widget.TabHost;  
  6. public class TabContact extends TabActivity {  
  7.     /** Called when the activity is first created. */  
  8.       @Override    
  9.          public void onCreate(Bundle savedInstanceState) {    
  10.              super.onCreate(savedInstanceState);    
  11.              //setContentView(R.layout.main);    
  12.                  
  13.              // 获得当前TabActivity的TabHost    
  14.             TabHost tabHost = getTabHost();     
  15.                           
  16.                     LayoutInflater.from(this).inflate(R.layout.tabsl, tabHost.getTabContentView(), true);     
  17.                  
  18.                      tabHost.addTab(tabHost.newTabSpec("tab1")     
  19.                               .setIndicator("键盘拨号")    
  20.                               .setContent(R.id.view1));                                   
  21.                          
  22.                       tabHost.addTab(tabHost.newTabSpec("tab2")     
  23.                               .setIndicator("通讯录")     
  24.                               .setContent(R.id.view2));     
  25.                       tabHost.addTab(tabHost.newTabSpec("tab3")     
  26.                               .setIndicator("联系人")     
  27.                              // .setContent(R.id.view3));  
  28.                               .setContent(new Intent(this, GContact.class)));   
  29.                         
  30.                       tabHost.addTab(tabHost.newTabSpec("tab4")     
  31.                               .setIndicator("收藏夹")     
  32.                               .setContent(R.id.view4));    
  33.          }   
  34. }  
import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.widget.TabHost; public class TabContact extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); // 获得当前TabActivity的TabHost TabHost tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.tabsl, tabHost.getTabContentView(), true); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("键盘拨号") .setContent(R.id.view1)); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("通讯录") .setContent(R.id.view2)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("联系人") // .setContent(R.id.view3)); .setContent(new Intent(this, GContact.class))); tabHost.addTab(tabHost.newTabSpec("tab4") .setIndicator("收藏夹") .setContent(R.id.view4)); } }

 

GContact.java

  1. import android.app.AlertDialog;  
  2. import android.app.ListActivity;  
  3. import android.content.DialogInterface;  
  4. import android.content.Intent;  
  5. import android.database.Cursor;  
  6. import android.net.Uri;  
  7. import android.os.Bundle;  
  8. import android.util.Log;  
  9. import android.view.Menu;  
  10. import android.view.MenuItem;  
  11. import android.view.View;  
  12. import android.widget.AdapterView;  
  13. import android.widget.ListAdapter;  
  14. import android.widget.ListView;  
  15. import android.widget.SimpleCursorAdapter;  
  16. public class GContact extends ListActivity{  
  17.     ListView contactList;  
  18.     ListAdapter adapter;  
  19.     Cursor c;  
  20.     @Override    
  21.     public void onCreate(Bundle savedInstanceState) {    
  22.         super.onCreate(savedInstanceState);    
  23.         setContentView(R.layout.contact_list);     
  24.           
  25.         contactList = (ListView)findViewById(android.R.id.list);  
  26.        
  27.         setAdapter();  
  28.         contactList.setOnItemLongClickListener(longClickItemListener);  
  29.     }  
  30.       
  31.     AdapterView.OnItemLongClickListener longClickItemListener = new AdapterView.OnItemLongClickListener() {  
  32.         public boolean onItemLongClick(AdapterView<?> arg0, View arg1,  
  33.                 int arg2, long arg3) {                        
  34.             Log.i("","...............string=="+c.getString(1));  
  35.                            
  36.              final CharSequence[] items = {"查看联系人""编辑联系人""删除联系人"};  
  37.              AlertDialog.Builder builder = new AlertDialog.Builder(GContact.this);  
  38.              builder.setTitle(c.getString(1));  
  39.              builder.setItems(items, new DialogInterface.OnClickListener() {  
  40.                  public void onClick(DialogInterface dialog, int item) {  
  41.                      //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();  
  42.                      if(item==0){  
  43.                          Log.i("",".................view contact...........");  
  44.                      }  
  45.                      else if(item==1){  
  46.                          Log.i("",".................edit contact............");  
  47.                          Intent intent = new Intent(GContact.this,AddContact.class);  
  48.                          intent.setAction(AddContact.EDIT_TABLE_ACTION);  
  49.                          Uri uri = Uri.parse(ContactProvider.CONTENT_URI+"/"+c.getString(0));     
  50.                          intent.setData(uri);                         
  51.                          startActivity(intent);  
  52.                      }  
  53.                      else if(item==2){  
  54.                          Log.i("","...................del contact............");  
  55.                          new AlertDialog.Builder(GContact.this)     
  56.                              .setIcon(R.drawable.stat_sys_warning)  
  57.                              .setTitle("删除")     
  58.                              .setMessage("将会删除此联系人")                               
  59.                              .setPositiveButton("确定"new DialogInterface.OnClickListener() {  
  60.                                    public void onClick(DialogInterface dialog, int id) {                                        
  61.                                        Uri uri = Uri.parse(ContactProvider.CONTENT_URI+"/"+c.getString(0));                                     
  62.                                        getContentResolver().delete(uri, nullnull);                                             
  63.                                       // getContentResolver().update(uri, null, null,null);   
  64.                                        setAdapter();  
  65.                                    }  
  66.                               })  
  67.                              .setNegativeButton("取消"new DialogInterface.OnClickListener() {  
  68.                                    public void onClick(DialogInterface dialog, int id) {  
  69.                                         dialog.cancel();  
  70.                                    }  
  71.                               })  
  72.                              .show();  
  73.                      }  
  74.                  }  
  75.              });  
  76.                
  77. //           builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {   
  78. //               public void onClick(DialogInterface dialog, int item) {   
  79. //                   Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();   
  80. //               }   
  81. //           });  
  82.              AlertDialog alert = builder.show();  
  83.               
  84.             return false;  
  85.         }  
  86.     };  
  87.       
  88.     private void setAdapter()  
  89.     {     
  90.         Uri uri = ContactProvider.CONTENT_URI;//getIntent().getData();  
  91.         Log.i("",".................uri.........."+uri);  
  92.           
  93.         c = getContentResolver().query(uri, nullnullnullnull);  
  94.         startManagingCursor(c);  
  95.         //c.moveToFirst();  
  96.         adapter = new SimpleCursorAdapter(this,R.layout.contact_list_item, c,  
  97.                 new String[] {"name"},   
  98.                 new int[] {R.id.name_list});  
  99.         setListAdapter(adapter);  
  100.           
  101. //        Cursor cursor = managedQuery(getIntent().getData(), null, null, null,null);  
  102. //        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_list_item, cursor,  
  103. //                new String[] {"name"},   
  104. //                new int[] {R.id.name_list});  
  105. //        setListAdapter(adapter);  
  106.     }  
  107.       
  108.     @Override  
  109.     public boolean onCreateOptionsMenu(Menu menu) {  
  110.         this.getMenuInflater().inflate(R.menu.option_menu, menu);  
  111.         return true;  
  112.     }  
  113.       
  114.     @Override  
  115.     public boolean onOptionsItemSelected(MenuItem item) {         
  116.         switch (item.getItemId()) {  
  117.         case R.id.item_add:  
  118.             Intent intent = new Intent(this,AddContact.class);  
  119.             intent.setAction(AddContact.INSERT_TABLE_ACTION);  
  120.             //intent.setData(getIntent().getData());  
  121.             Log.i("","*************************CContent....uri="+getIntent().getData());  
  122.             startActivity(intent);  
  123.               
  124.             //startActivity(new Intent(this, AddContact.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));  
  125.           //  startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData()));  
  126.             return true;             
  127.         case R.id.item_search:            
  128.             return true;  
  129.         }  
  130.         return super.onOptionsItemSelected(item);  
  131.      }  
  132.       
  133. }  
import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter; public class GContact extends ListActivity{ ListView contactList; ListAdapter adapter; Cursor c; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contact_list); contactList = (ListView)findViewById(android.R.id.list); setAdapter(); contactList.setOnItemLongClickListener(longClickItemListener); } AdapterView.OnItemLongClickListener longClickItemListener = new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Log.i("","...............string=="+c.getString(1)); final CharSequence[] items = {"查看联系人", "编辑联系人", "删除联系人"}; AlertDialog.Builder builder = new AlertDialog.Builder(GContact.this); builder.setTitle(c.getString(1)); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); if(item==0){ Log.i("",".................view contact..........."); } else if(item==1){ Log.i("",".................edit contact............"); Intent intent = new Intent(GContact.this,AddContact.class); intent.setAction(AddContact.EDIT_TABLE_ACTION); Uri uri = Uri.parse(ContactProvider.CONTENT_URI+"/"+c.getString(0)); intent.setData(uri); startActivity(intent); } else if(item==2){ Log.i("","...................del contact............"); new AlertDialog.Builder(GContact.this) .setIcon(R.drawable.stat_sys_warning) .setTitle("删除") .setMessage("将会删除此联系人") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri.parse(ContactProvider.CONTENT_URI+"/"+c.getString(0)); getContentResolver().delete(uri, null, null); // getContentResolver().update(uri, null, null,null); setAdapter(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); } } }); // builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog, int item) { // Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); // } // }); AlertDialog alert = builder.show(); return false; } }; private void setAdapter() { Uri uri = ContactProvider.CONTENT_URI;//getIntent().getData(); Log.i("",".................uri.........."+uri); c = getContentResolver().query(uri, null, null, null, null); startManagingCursor(c); //c.moveToFirst(); adapter = new SimpleCursorAdapter(this,R.layout.contact_list_item, c, new String[] {"name"}, new int[] {R.id.name_list}); setListAdapter(adapter); // Cursor cursor = managedQuery(getIntent().getData(), null, null, null,null); // SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_list_item, cursor, // new String[] {"name"}, // new int[] {R.id.name_list}); // setListAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { this.getMenuInflater().inflate(R.menu.option_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.item_add: Intent intent = new Intent(this,AddContact.class); intent.setAction(AddContact.INSERT_TABLE_ACTION); //intent.setData(getIntent().getData()); Log.i("","*************************CContent....uri="+getIntent().getData()); startActivity(intent); //startActivity(new Intent(this, AddContact.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); // startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData())); return true; case R.id.item_search: return true; } return super.onOptionsItemSelected(item); } }

 

AddContact.java

  1. import android.app.Activity;  
  2. import android.content.ContentValues;  
  3. import android.content.Intent;  
  4. import android.database.Cursor;  
  5. import android.net.Uri;  
  6. import android.os.Bundle;  
  7. import android.util.Log;  
  8. import android.view.View;  
  9. import android.view.View.OnClickListener;  
  10. import android.widget.Button;  
  11. import android.widget.EditText;  
  12. public class AddContact extends Activity implements OnClickListener{  
  13.     private EditText nameText,telText;    
  14.     private Button saveBtn,cancleBtn;  
  15.     private String mState;  
  16.     Uri uri;  
  17.       
  18.     public static final String INSERT_TABLE_ACTION = "insert";  
  19.     public static final String EDIT_TABLE_ACTION = "edit";  
  20.     @Override  
  21.     public void onCreate(Bundle savedInstanceState){  
  22.         super.onCreate(savedInstanceState);  
  23.         setContentView(R.layout.create_contact);      
  24.               
  25.         nameText = (EditText)findViewById(R.id.name);  
  26.         telText = (EditText)findViewById(R.id.tel);  
  27.           
  28.         saveBtn = (Button)findViewById(R.id.savebtn);  
  29.         cancleBtn = (Button)findViewById(R.id.canclebtn);  
  30.         saveBtn.setOnClickListener(this);  
  31.         cancleBtn.setOnClickListener(this);  
  32.           
  33.         Intent intent = getIntent();  
  34.         String action = intent.getAction();  
  35.           
  36.         if(EDIT_TABLE_ACTION.equals(action)){  
  37.             mState="edit";  
  38.             uri = intent.getData();  
  39.             Log.i("",">>>>>>>>>>>>>>>>>>>>>>>>>>"+uri);  
  40.             Cursor c = getContentResolver().query(uri, null"_id="+uri.getPathSegments().get(1), nullnull);  
  41.             //Cursor c = managedQuery(uri,null,null,null,null);  
  42.             c.moveToFirst();  
  43.             Log.i("","**************get(1)==="+uri.getPathSegments().get(1));  
  44.             Log.i("","....c.getString(1)="+c.getString(1)+"......."+c.getString(2));  
  45.             nameText.setTextKeepState(c.getString(1));  
  46.             telText.setTextKeepState(c.getString(2));  
  47.         }  
  48.           
  49.     }  
  50.       
  51.     public void onClick(View v){  
  52.       
  53.           
  54.         if(v == saveBtn){  
  55.             ContentValues values = new ContentValues();  
  56.             values.put("name", nameText.getText().toString());  
  57.             values.put("tel", telText.getText().toString());  
  58.               
  59.             if(mState=="edit"){ //编辑  
  60.                 getContentResolver().update(uri, values, "_id="+uri.getPathSegments().get(1), null);  
  61.             }else{  //插入  
  62.                 if(nameText.getText().length()!=0){                   
  63.                     getContentResolver().insert(ContactProvider.CONTENT_URI, values);  
  64.                 }     
  65.             }  
  66.             finish();   
  67.               
  68.         }  
  69.         else if(v == cancleBtn){  
  70.             finish();  
  71.         }                 
  72.     }  
  73. }  
import android.app.Activity; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class AddContact extends Activity implements OnClickListener{ private EditText nameText,telText; private Button saveBtn,cancleBtn; private String mState; Uri uri; public static final String INSERT_TABLE_ACTION = "insert"; public static final String EDIT_TABLE_ACTION = "edit"; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.create_contact); nameText = (EditText)findViewById(R.id.name); telText = (EditText)findViewById(R.id.tel); saveBtn = (Button)findViewById(R.id.savebtn); cancleBtn = (Button)findViewById(R.id.canclebtn); saveBtn.setOnClickListener(this); cancleBtn.setOnClickListener(this); Intent intent = getIntent(); String action = intent.getAction(); if(EDIT_TABLE_ACTION.equals(action)){ mState="edit"; uri = intent.getData(); Log.i("",">>>>>>>>>>>>>>>>>>>>>>>>>>"+uri); Cursor c = getContentResolver().query(uri, null, "_id="+uri.getPathSegments().get(1), null, null); //Cursor c = managedQuery(uri,null,null,null,null); c.moveToFirst(); Log.i("","**************get(1)==="+uri.getPathSegments().get(1)); Log.i("","....c.getString(1)="+c.getString(1)+"......."+c.getString(2)); nameText.setTextKeepState(c.getString(1)); telText.setTextKeepState(c.getString(2)); } } public void onClick(View v){ if(v == saveBtn){ ContentValues values = new ContentValues(); values.put("name", nameText.getText().toString()); values.put("tel", telText.getText().toString()); if(mState=="edit"){ //编辑 getContentResolver().update(uri, values, "_id="+uri.getPathSegments().get(1), null); }else{ //插入 if(nameText.getText().length()!=0){ getContentResolver().insert(ContactProvider.CONTENT_URI, values); } } finish(); } else if(v == cancleBtn){ finish(); } } }

 

DBHelper.java

  1. import android.content.Context;  
  2. import android.database.sqlite.SQLiteDatabase;  
  3. import android.database.sqlite.SQLiteOpenHelper;  
  4. public class DBHelper extends SQLiteOpenHelper  
  5. {  
  6.     public static final String DATABASE_NAME = "bbkcontact.db";  
  7.     private final static int VERSION = 3;  
  8.       
  9.     public DBHelper(Context context) {  
  10.         super(context, DATABASE_NAME, null, VERSION);         
  11.     }  
  12.     @Override  
  13.     public void onCreate(SQLiteDatabase db)   
  14.     {  
  15.         db.execSQL("CREATE TABLE contactstable ("+  
  16.                 "_id INTEGER PRIMARY KEY , "+  
  17.                 "name TEXT, " +  
  18.                 "tel TEXT);");  
  19.     }  
  20.     @Override  
  21.     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {        
  22.         db.execSQL("DROP TABLE IF EXISTS contactstable");  
  23.         onCreate(db);  
  24.     }  
  25. }  
import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DBHelper extends SQLiteOpenHelper { public static final String DATABASE_NAME = "bbkcontact.db"; private final static int VERSION = 3; public DBHelper(Context context) { super(context, DATABASE_NAME, null, VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE contactstable ("+ "_id INTEGER PRIMARY KEY , "+ "name TEXT, " + "tel TEXT);"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS contactstable"); onCreate(db); } }

 

ContactProvider.java

  1. import android.content.ContentProvider;  
  2. import android.content.ContentValues;  
  3. import android.content.UriMatcher;  
  4. import android.database.Cursor;  
  5. import android.database.sqlite.SQLiteDatabase;  
  6. import android.net.Uri;  
  7. import android.util.Log;  
  8. public class ContactProvider extends ContentProvider  
  9. {  
  10.     private DBHelper dbHelper;  
  11.       
  12.     //private static UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);  
  13.     public static final String AUTHORITY = "com.bbk.contact";  
  14.     //private static final int CONTACTS = 1;  
  15.       
  16.     public static final Uri CONTENT_URI = Uri.parse("content://"+AUTHORITY+"/contacts");  
  17.       
  18.     /* 
  19.     static{ 
  20.         URI_MATCHER.addURI(AUTHORITY, "contactstable", CONTACTS); 
  21.     } 
  22.     */  
  23.     public ContactProvider(){         
  24.     }  
  25.       
  26.     @Override  
  27.     public int delete(Uri uri, String selection, String[] selectionArgs) {  
  28.         SQLiteDatabase db = dbHelper.getWritableDatabase();   
  29.         String rowId = uri.getPathSegments().get(1);  
  30.         //Log.i("","...............rowId="+rowId);  
  31.         return db.delete("contactstable","_id = "+rowId, null);  
  32.     }  
  33.     @Override  
  34.     public String getType(Uri uri) {          
  35.         return null;  
  36.     }  
  37.     @Override  
  38.     public Uri insert(Uri uri, ContentValues values) {        
  39.         SQLiteDatabase db = dbHelper.getWritableDatabase();       
  40.           
  41.         long rowID = db.insert("contactstable"null, values);  
  42.         if(rowID > 0){  
  43.             Uri url = Uri.parse("content://" + AUTHORITY + "/contactstalbe" + "/" + rowID);  
  44.             Log.i("",".............run insert.........url="+url);  
  45.             return url;  
  46.         }  
  47.         return null;  
  48.     }  
  49.     @Override  
  50.     public boolean onCreate() {  
  51.         dbHelper = new DBHelper(getContext());        
  52.         return true;  
  53.     }  
  54.     @Override  
  55.     public Cursor query(Uri uri, String[] projection, String selection,  
  56.             String[] selectionArgs, String sortOrder) {  
  57.           
  58.         SQLiteDatabase db = dbHelper.getReadableDatabase();  
  59.         //"_id = "+uri.getPathSegments().get(1)  
  60.           
  61.         return db.query("contactstable", projection, selection, selectionArgs, nullnull, sortOrder);  
  62.     }  
  63.     @Override  
  64.     public int update(Uri uri, ContentValues values, String selection,  
  65.             String[] selectionArgs) {  
  66.         SQLiteDatabase db = dbHelper.getWritableDatabase();   
  67.         String rowId = uri.getPathSegments().get(1);  
  68.         Log.i("","...............rowId="+rowId);  
  69.         return db.update("contactstable",values,"_id = "+rowId, null);  
  70.           
  71.     }  

引用:http://blog.csdn.net/dany1202/article/details/6088865
  评论这张
 
阅读(1690)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018