2016-04-30 78 views
0

我已經獲得了所有聯繫數(名稱,數字)在數組中並顯示在列表視圖中..我已經知道如何使用抽頭將單個值插入到數據庫中,但我不知道如何插入數組。如何獲取數組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 ..

回答

0

你應該通過String作爲第二PARAM但是你逝去的String [];如果您只是需要的ArrayList然後可以轉換的String []到列表中看到this

0

您可以爲插件組做這樣的事情

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()); 
} 
相關問題