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,但剛開錯誤「8月4日至三十○日:如果我改變extends ListActivity
到extends Activity
,該
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'"
:30:45.234代碼工作就好了我如何使它工作使用extends ListActivity
??
您的內容必須有一個ListView其id屬性爲「android.R.id.list」「 – njzk2 2013-04-30 08:47:02