不幸的是HelloListView已经停止 [英] Unfortunately HelloListView has stopped

查看:176
本文介绍了不幸的是HelloListView已经停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照本教程但是当我尝试跑我得到了应用程序不幸的是HelloListView已停止 该IDE没有给出警告或错误。

I've followed this tutorial but when I try to run the application I get Unfortunately HelloListView has stopped The IDE gives no warnings or errors.

我的HelloViewListActivity.java看起来是这样的:

My HelloViewListActivity.java looks like this:

public class HelloListViewActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String[] countries = getResources().getStringArray(R.array.countries_array);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text
                Toast.makeText(getApplicationContext(),
                        ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}

我的strings.xml和list_item.xml都是完全相同教程。

的logcat这里登录 它是什么,我做错了什么?

Logcat log here What is it that I am doing wrong?

推荐答案

您必须添加的setContentView(R.layout.yourlayout) super.onCreate(savedInstanceState);

R.layout.yourlayout 应该是这样的(文件夹RES /布局):

the R.layout.yourlayout should look like this ( in folder res/layout ) :

<?xml version="1.0" encoding="utf-8"?>
<ListView 
  android:id="@android:id/list"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" />

这篇关于不幸的是HelloListView已经停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆