如何获取数组android中的所有值并插入到数据库中

问题描述:

我已经获得了所有联系数(名称,数字)在数组中并显示在列表视图中..我已经知道如何使用抽头将单个值插入到数据库中,但我不知道如何插入数组。如何获取数组android中的所有值并插入到数据库中

 cursor1 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); 
     startManagingCursor(cursor1); 

     String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID}; 

     int[] to = {android.R.id.text1, android.R.id.text2}; 

     SimpleCursorAdapter listadapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor1, from, to); 
     setListAdapter(listadapter); 
     lv = getListView(); 

凌空

@Override 
      protected Map<String, String> getParams() throws AuthFailureError { 
       Map<String,String> params = new HashMap<>(); 
       //Adding parameters to request 
       params.put("fromV", from); 

我在得到错误从params.put ..

你应该通过String作为第二PARAM但是你逝去的String [];如果您只是需要的ArrayList然后可以转换的String []到列表中看到this

您可以为插件组做这样的事情

public void Insert_phone_contact(String [] contact){//Arrary of your contacts 
try{ 

SQLiteDatabase DB = this.getWritableDatabase(); 
ContentValues cv = new ContentValues(); //put your contacts in the content values in the loop 
for(int i=0;i<contact.length;i++){    
    cv.put(CONTACT_NAME, contact[i]); 
    DB.insert(TABLE_CONTACTS, null, cv); //Insert each time for loop count    
} 
DB.close(); // Now close the DB Object 
} 
catch(Exception ex){ 
Log.e("Error in phone contact insertion", ex.toString()); 
}