安卓contactlist [英] android contactlist

查看:169
本文介绍了安卓contactlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想获得使用联系人应用程序在模拟器中显示一个类似的联系人列表创建联系人
是不是有什么不对吗?

布局

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
    <的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=姓名:
    />
    <的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / CONTACT_NAME/>
< / LinearLayout中>

codeS

 包fypj.e;进口android.app.ListActivity;
进口android.database.Cursor;
进口android.os.Bundle;
进口android.provider.Contacts.People;
进口android.provider.ContactsContract.CommonDataKinds.Phone;
导入android.widget *。公共E类扩展ListActivity {
    私人SimpleCursorAdapter myAdapter;
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        。光标光标= getContentResolver()查询(People.CONTENT_URI,NULL,NULL,NULL,NULL);
        startManagingCursor(光标);        的String [] =列新的String [] {} Phone.LABEL;
        INT [] =名新INT [] {} R.id.contact_name;
        myAdapter =新SimpleCursorAdapter(这一点,R.layout.main,光标,列名);
        setListAdapter(myAdapter);
    }
}


解决方案

我想你需要允许你的清单文件添加到联系人。

Would like to get the contacts created using the contacts app in the emulator and display like a contact list Is there something wrong?

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Name: "
    />
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/contact_name"/>
</LinearLayout>

codes

package fypj.e;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.*;

public class e extends ListActivity {
    private SimpleCursorAdapter myAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
        startManagingCursor(cursor);

        String[] column = new String[] {Phone.LABEL};
        int[] names = new int[] {R.id.contact_name};
        myAdapter = new SimpleCursorAdapter(this, R.layout.main, cursor, column, names);
        setListAdapter(myAdapter);
    }
}

解决方案

I think you need to add permission to your manifest file to access contacts.

这篇关于安卓contactlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆