gpt4 book ai didi

java - Android傻瓜代码错误

转载 作者:行者123 更新时间:2023-12-02 07:48:31 25 4
gpt4 key购买 nike

傻瓜式 Android 应用程序开发中,我在最后一段代码后收到错误。

The method setListAdapter(ArrayAdapter<String>) is undefined for the type ReminderListActivity

代码如下:

package com.dummies.android.taskreminder;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ReminderListActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);

String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin"};
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
setListAdapter(adapter);
}
}

最佳答案

在我看来就像 Activity没有 setListAdapter() 但它的子类 ListActivity做。也许你想要

public class ReminderListActivity extends ListActivity {

相反?这应该可以正常工作:

package com.dummies.android.taskreminder;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ReminderListActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);

String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin"};
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
setListAdapter(adapter);
}
}

关于java - Android傻瓜代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10525881/

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