改变这个:public class HelloListView extends Activity { to:public class HelloListView扩展ListActivity { 并添加: 查看源 打印?
1 import android.widget.ArrayAdapter; 2 import android.app.ListActivity;
数组的代码应该在onCreate方法之后。
我也遇到了模拟器的问题。我得到了“应用程序意外停止...”的消息。
我和你有同样的路线:
public class HelloListView extends ListActivity {
在我的HelloListView Manifest中,我有以下行:
<activity android:name=".HelloListViewActivity"
当我把它变成:
<activity android:name=".HelloListView"
应用程序开始在模拟器中工作。将类重命名为HelloListViewActivity也可能会执行相同的操作。还没试过......
view没有方法getText(),TextView有方法getText(),TextView扩展View, 所以你的代码必须像:
Toast.makeText(getApplicationContext(), ((TextView) view).getText());
你必须阅读android SDK的api。
Toast.makeText(getApplicationContext(), ((View) view).getText()
应该
Toast.makeText(getApplicationContext(), ((TextView) view).getText()
View类没有实现getText方法,而TextView扩展了View并实现了getText方法。在您的代码中,您将视图转换为视图,这实际上没有做任何事情。它需要转换为TextView才能正常工作。
我在想你可能会放置你的 COUNTRIES 字符串数组也在错误的位置。
COUNTRIES
粘贴所有你的 HelloListView 如果您仍无法解决问题,请在您的问题中输入代码。
HelloListView
此外,这可能是一个很好的阅读: http://developer.android.com/guide/topics/ui/index.html