Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android中使用onListItemClick在listView中打开联系人详细信息卡并显示联系人姓名?_Java_Android_Listview_Android Arrayadapter_Listactivity - Fatal编程技术网

Java 如何在Android中使用onListItemClick在listView中打开联系人详细信息卡并显示联系人姓名?

Java 如何在Android中使用onListItemClick在listView中打开联系人详细信息卡并显示联系人姓名?,java,android,listview,android-arrayadapter,listactivity,Java,Android,Listview,Android Arrayadapter,Listactivity,我有一个联系人应用程序,它显示联系人的所有姓名,带有ArrayAdapter。这很好,但我想在每次单击姓名时打开带有联系人详细信息的本机联系人应用程序 提前谢谢你 public class MainActivity extends ListActivity { private CustomAdapter customAdapter; List<String> contacts = new ArrayList<String>(); @Override protect

我有一个联系人应用程序,它显示联系人的所有姓名,带有ArrayAdapter。这很好,但我想在每次单击姓名时打开带有联系人详细信息的本机联系人应用程序

提前谢谢你

public class MainActivity extends ListActivity {


private CustomAdapter customAdapter;

List<String> contacts = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    ListView lv = (ListView) findViewById(android.R.id.list);
    customAdapter = new CustomAdapter(this);
    lv.setAdapter(customAdapter);

}

@Override
protected void onResume() {
    super.onResume();
    Log.d("TAG","onresume");
    loadApps();
}





public void loadApps(){

    //Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    Cursor cursor;
    ContentResolver contentResolver = getContentResolver();
    cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI,null,
            ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1",
            null,
            "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");





    customAdapter.clear();
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();

        do {
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

            contacts.add(name);

        } while (cursor.moveToNext());
    }
    cursor.close();

    for (String names : contacts) {

        AppInfoItem appInfoItem = new AppInfoItem();

        appInfoItem.name = names;

        customAdapter.add(appInfoItem);

    }
}



@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("content://contacts/people/"));

    if (intent != null) {
        startActivity(intent);
    }

}
}

我认为您需要使用
Intent
,并将Intent数据设置为表单联系人的URI

content://contacts/people/1

如第一个示例所示

您检查了吗?我觉得这是一个重复的问题。这不是重复的问题,前面的问题需要一种方法来选择联系人并将其姓名返回给呼叫应用程序。在这个问题上,OP已经有了一个联系人列表,并且想要调用内置联系人应用程序来显示该联系人的全部详细信息。我已经尝试了你的方法,但是当我点击一个名字时,应用程序就会崩溃,我猜1代表一个特定的ID或其他什么,我不明白下面的代码是:Intent Intent=new Intent(Intent.ACTION_视图,Uri.parse(“content://contacts/people/“”);if(intent!=null){startActivity(intent);}是的,1必须替换为联系人的ID。您可以更新您的问题以包含更多活动的代码吗?请尝试删除任何完全无关的内容,但查看您在哪里运行代码的第一部分会很有用。如何将ID输入变量,是否必须在onListIte中再次运行光标McClicked或者什么是最好的方式?你需要
许可才能阅读联系人我一小时后回来,如果到时没有可接受的答案,我回来后会查看你的完整代码。
public class AppInfoItem {

String name;
String id;


}
content://contacts/people/1