Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.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
Android 没有ListActivity的SimpleCorsorAdapter?_Android_Database_Eclipse_Sqlite_Simplecursoradapter - Fatal编程技术网

Android 没有ListActivity的SimpleCorsorAdapter?

Android 没有ListActivity的SimpleCorsorAdapter?,android,database,eclipse,sqlite,simplecursoradapter,Android,Database,Eclipse,Sqlite,Simplecursoradapter,您能给我一些关于如何在没有ListActivity的情况下使用SimpleCorsAdapter的提示吗? 我的意思是,我想开发一个使用SimpleCorsorAdapter而不使用listActivity的应用程序, 坦白地说,如果我不使用ListActivity,我应该如何设置SimpleCursAdapter项, 比如说 ListAdapter=new SimpleCorsorAdapter(这是android.R.layout.two_line_list_项目,光标,从,到);或许

您能给我一些关于如何在没有ListActivity的情况下使用SimpleCorsAdapter的提示吗? 我的意思是,我想开发一个使用SimpleCorsorAdapter而不使用listActivity的应用程序, 坦白地说,如果我不使用ListActivity,我应该如何设置SimpleCursAdapter项, 比如说


ListAdapter=new SimpleCorsorAdapter(这是android.R.layout.two_line_list_项目,光标,从,);或许


或许

ListAdapter=new SimpleCursorAdapter(这个.R.layout.mypage,光标,从,


我的问题是“”项,因为我在这个页面(XML文件)中没有任何文本视图,我有一个树字段,我想显示在listView中,我在XML文件中定义为“mylist”,在您的活动中

private String [] project = {ContactsContract.CommonDataKinds.Phone._ID,
            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, 
            ContactsContract.CommonDataKinds.Phone.NUMBER};

...

    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                        project, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
    startManagingCursor(phones);
    ContactCursorAdapter adapter = new ContactCursorAdapter(this, phones);
    ListView contactLV = (ListView) findViewById(R.id.contactLV);
    contactLV.setAdapter(adapter);
...
您自己的游标适配器类

 public class ContactCursorAdapter extends CursorAdapter {

        public ContactCursorAdapter(Context context, Cursor c) {
            super(context, c);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            TextView nameTV = (TextView)view.findViewById(R.id.nameTV);
            nameTV.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
            TextView phoneTV = (TextView)view.findViewById(R.id.phoneTV);
            phoneTV.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View v = inflater.inflate(R.layout.contact_for_lv, parent, false);
            bindView(v, context, cursor);
            return v;
        }


}
ListView的XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="5dp" >

    <TextView
        android:id="@+id/nameTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textSize="18sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/phoneTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textSize="14sp" />

</LinearLayout>


谢谢您的回答,但请您解释一下,我不明白,我应该在哪里定义Textview?其中XML文件,在我的XML文件中没有TextView,它只包括ListView和一些按钮。TextView您必须在contact_中为_lv.XML文件定义。有些视图可能是ListView的项(行)。