在傻瓜式 Android 应用程序开发中,我在最后一段代码后收到错误。
The method
setListAdapter(ArrayAdapter<String>)
is undefined for the typeReminderListActivity
代码如下:
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/