我正在制作一个联系人备份应用程序,并希望在列表视图中显示联系人。我编写的代码正在执行此操作,但显示的信息格式不正确。我想从现在在列表视图中显示的信息中提取姓名和联系电话。我这样做的代码如下......谁能指导我如何从这里生成的联系信息中提取姓名和号码?我不需要明确的代码,只需指出我需要遵循的方向。谢谢
public class ContactsBackupMain extends Activity {
Cursor cursor;
ArrayList<String> vCard;
//String vfile;
File vfile;
Button btnCreateBackup;
static Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts_backup_main);
mContext = ContactsBackupMain.this;
// vfile = "Contacts" + "_" + System.currentTimeMillis()+".vcf";
btnCreateBackup = (Button)findViewById(R.id.btnCreateBackup);
btnCreateBackup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getContactsBackup();
Intent intent = new Intent(ContactsBackupMain.this, DisplayListItems.class);
intent.putExtra("vCard", vCard);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.contacts_backup_main, menu);
return true;
}
private void getContactsBackup() {
String path1 = Environment.getExternalStorageDirectory()
.getPath() + "/external_sd/";
File dir = new File(path1);
if(!dir.exists())
dir.mkdirs();
vfile = new File(dir, "Contacts.vcf");
vfile.canWrite();
vCard = new ArrayList<String>();
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
if(cursor!=null && cursor.getCount()>0)
{
cursor.moveToFirst();
for(int i=0; i<cursor.getCount(); i++)
{
get(cursor);
Toast.makeText(getApplicationContext(), "Contact " + (i+1) + "VCF String is " + vCard.get(i), Toast.LENGTH_LONG).show();
cursor.moveToNext();
}
}else{
Toast.makeText(getApplicationContext(), "No Contacts in Your Phone", Toast.LENGTH_LONG).show();
}
}