如何在android java中将List <object>转换为List <string>

时间:2016-03-13 09:18:56

标签: android

这是来自contactHandlerDatabase类

public List<Contact> displayAllContact(){

    //display all the contact in repertoire
    List<Contact> AllContactList= new ArrayList<Contact>();//create the arraylist of contact

    SQLiteDatabase db=this.getWritableDatabase();//in writable mode

    Cursor cursor=db.rawQuery(SELECT_ALL_QUERY+TABLE_NAME,null);


    if(cursor.moveToFirst()){

        do{//capture data of all columns in each row

            Contact contact=new Contact();

            contact.setContactName(cursor.getString(0));

            contact.setContactSurname(cursor.getString(1));

            contact.setContactTel(Integer.parseInt(cursor.getString(2)));

            contact.setContactEmail(cursor.getString(3));

            AllContactList.add(contact);//add all column data to list

        }while (cursor.moveToNext());

    }//end if

    return AllContactList;

}

这是来自CallHistory类

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);


    List<Contact> AllContactList;

    switch (requestCode){

        case REQ_CODE_SPEECH_INPUT:{

            if ((resultCode == RESULT_OK) && (data != null)) {


                ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

               AllContactList=db.displayAllContact();

**enter code here**

                ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.activity_repertoire,R.id.lblCallHistory,AllContactList);


            }//end if

            else{
                convertToSpeech("Discours incoherent");
            }//end else

        }//end case

        break;

    }//end switch

}//end of onActivityResult method

我不知道如何在ArrayAdapter中实现AllContactList,因为它正在请求List作为参数。请帮助

0 个答案:

没有答案