热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用对象列表填充ListView-PopulateListViewwithListofObjects

IhavelistiftwitterstatusesandIwanttopopulateitinalistview我有列表是否有twitter状态,我想在列表视图中填充它

I have list if twitter statuses and I want to populate it in a listview

我有列表是否有twitter状态,我想在列表视图中填充它

public class TwitterTimeline extends Activity {
    List statuses;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_twitter_timeline);
        setTitle("Timeline");
        ListView listview = (ListView) findViewById(R.id.listView);
        Bundle b = this.getIntent().getExtras();
        if (b != null) {
            MyStatuses myStatuses = (MyStatuses) b.getSerializable("statuses");
            statuses = myStatuses.statuses;
            for (Status st : statuses) {// this prints all the status on the  catlog
                Log.d("Abharthan : ", st.getUser().getScreenName()+ ":" + st.getText());

            }

            ArrayAdapter adapter = new ArrayAdapter(this,
                    android.R.layout.simple_list_item_1, statuses);// this line is giving error

            listview.setAdapter(adapter);
        }

    }

Here MyStatus Class is:

这里的MyStatus类是:

import java.io.Serializable;
import java.util.List;

import twitter4j.Status;

public class MyStatuses implements Serializable {
    List statuses;
}

The layout file containing list view is android_twitter_timeline.xml:

包含列表视图的布局文件是android_twitter_timeline.xml:



    


How can I populate my listview with twitter statuses using ArrayAdapter or any other method.

如何使用ArrayAdapter或任何其他方法使用twitter状态填充我的列表视图。

3 个解决方案

#1


0  

Basically, you will have to create an ArrayAdapter with your own data type. Inside, the adapter, you will populate the view for each row in the ListView.

基本上,您必须使用自己的数据类型创建ArrayAdapter。在适配器内部,您将为ListView中的每一行填充视图。

Then, set that adapter to your ListView.

然后,将该适配器设置为ListView。

Please check out this guide Using an ArrayAdapter with ListView. And you will got to use "Using a Custom ArrayAdapter"

请查看本指南使用带ListView的ArrayAdapter。你必须使用“使用自定义ArrayAdapter”

#2


0  

You can use a ArrayAdapter or BaseAdapter, here is a example with code, HERE

您可以使用ArrayAdapter或BaseAdapter,以下是代码示例,HERE

#3


0  

Please change the ArrayAdapter from MyStatuses to Status

请将ArrayAdapter从MyStatuses更改为Status


推荐阅读
author-avatar
年轻人创事业的美丽家园
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有