gpt4 book ai didi

java - setListAdapter() 不起作用

转载 作者:行者123 更新时间:2023-12-01 18:46:42 26 4
gpt4 key购买 nike

import android.app.Activity;
import android.os.Bundle;
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri allContacts = Uri.parse("content://contacts/people");
Cursor c = managedQuery(allContacts, null, null, null, null);
String[] columns = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID};
int[] views = new int[] {R.id.contactName, R.id.contactID};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.activity_main, c, columns,views);
this.setListAdapter(adapter);
}

}

它总是显示此错误:方法 setListAdapter(SimpleCursorAdapter) 未定义类型 MainActivity

最佳答案

为了使用setListAdapter,您的类必须扩展ListActivity而不是Activity。改变

public class MainActivity extends Activity

public class MainActivity extends ListActivity 

关于java - setListAdapter() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17510724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com