public class ListPage extends ListActivity
{
ListView months;
ArrayAdapter my;
String[] monthlist = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sept", "oct", "nov", "dec"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.list_page);
months = (ListView)findViewById(R.id.list);
my = new ArrayAdapter(this,android.R.layout.simple_list_item_1,monthlist);
months.setAdapter(my);
}
}
我正在尝试从另一个活动中启动此 ListActivity,但出现错误“04-30 08:30:45.234:
E/AndroidRuntime(2010): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.listinflator_demo/com.example.listinflator_demo.
ListPage}: java.lang.RuntimeException: Your content must have a ListView
whose id attribute is 'android.R.id.list'"
如果我更改extends ListActivity
为extends Activity
,则代码可以正常工作。我如何使它工作使用extends ListActivity
?