首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListActivity不显示

ListActivity不显示
EN

Stack Overflow用户
提问于 2011-10-15 11:36:07
回答 3查看 213关注 0票数 0

在下面的应用程序中,选项卡可以正确显示,但我不能确定为什么列表视图不显示。有什么建议可以帮上忙。它没有崩溃,但我得到了一个错误代码:任何帮助都将不胜感激。

代码语言:javascript
复制
10-14 20:27:32.728: ERROR/AndroidRuntime(1592): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dana/com.dana.DanaHillsActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dana/com.dana.RSSView}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

要启动的类代码:

代码语言:javascript
复制
public class RSSView extends ListActivity {

    private static RssListAdapter adapter;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        List<JSONObject> jobs = new ArrayList<JSONObject>();
        try {
            jobs = RssReader.getLatestRssFeed();
        } catch (Exception e) {
            Log.e("RSS ERROR", "Error loading RSS Feed Stream >> " + e.getMessage() + " //" + e.toString());
        }


        Log.d("id", "log this");
        adapter = new RssListAdapter(this,jobs);
        setListAdapter(adapter);


        setContentView(R.layout.rssview1);



    }
}

主代码:

代码语言:javascript
复制
public class DanaHillsActivity extends TabActivity {


    public static TabHost tabHost; 

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tabHost = (TabHost)findViewById(android.R.id.tabhost);

        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
        TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");
        /** TabSpec setIndicator() is used to set name for the tab. */
        /** TabSpec setContent() is used to set content for a particular tab. */



        firstTabSpec.setIndicator("1").setContent(new Intent(this,RSSView.class));
        secondTabSpec.setIndicator("2").setContent(new Intent(this,RSSView.class));
        thirdTabSpec.setIndicator("3").setContent(new Intent(this,RSSView.class));

        /** Add tabSpec to the TabHost to display. */
        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
        tabHost.addTab(thirdTabSpec);
    }
}

主.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

<TabHost android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost">
    <LinearLayout android:id="@+id/LinearLayout01"
      android:orientation="vertical" android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <TabWidget android:id="@android:id/tabs"
         android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
    </LinearLayout>
</TabHost>

rssview1.xml代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/wallpaper">

    <!-- List view -->
    <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:dividerHeight="0px"
        android:divider="#00000000" />  

</RelativeLayout>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-10-15 11:45:27

您的setContentView(R.layout.rssview1);需要出现在设置列表适配器的行之前。尝试将setContentView(R.layout.rssview1);放在super.onCreate(savedInstanceState);之后

票数 0
EN

Stack Overflow用户

发布于 2011-10-15 12:27:06

如果你使用的是List actvity,那么不需要设置setContentView(R.layout.layout_name);删除它。我认为你的list已经创建了,但是没有显示出来,因为你的布局覆盖了这个视图。因此,一旦删除行setContentView(R.layout.layout_name);

票数 0
EN

Stack Overflow用户

发布于 2011-10-15 13:06:07

您正在扩展ListActivity,因此您不需要从xml获取任何列表视图。

你可以得到像this这样的listview对象

并用它来设置适配器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7775581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档