0

我有json到可序列化的claas然后我用它来填充listview,一切正常,但我想用一个可序列化的对象在另一个xml页面上填充textview,我读到最好的方法是捆绑意图,但我做到了代码有问题。

public class FeedItem implements Serializable {

    private String title;
    private String date;
    private String attachmentUrl;
    private String id;
    private String content;
    private String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getAttachmentUrl() {
        return attachmentUrl;
    }

    public void setAttachmentUrl(String attachmentUrl) {
        this.attachmentUrl = attachmentUrl;
    }




    @Override
    public String toString() {
        return "[ title=" + title + ", date=" + date + "]";
    }

    ArrayList<FeedItem> all_thumbs = new ArrayList<FeedItem>();
    all_thumbs.add(new FeedItem(title);
    Intent intent = new Intent(title);

    Bundle extras = new Bundle();

    extras.putSerializable("title",title);
    intent.putExtras(extras);

}

在我想使用它的课堂上

public void updateList() {

    TextView infoz = (TextView) getView().findViewById(R.id.infoz);
    Bundle args;
    getArguments().getSerializable(title);
4

2 回答 2

0

如果您想传递任何原始数据类型值(String、int、long、float 等),则不需要使用 Bundle.putExtra(KEY,Serialized Object) 和 Bundle.getSerializable(KEY)。您可以使用 Bundle.putExtra(KEY,primitive data);

如果要将类对象传递给意图/捆绑,则需要在该类中实现 Serializable/Parsable,例如:

public class Test implements Serializable
{
   private static final long serialVersionUID = 1L;
   int test1;
} 

然后您可以将该对象实例传递给意图,例如:

myIntent.putExtra( KEY, new Test() );

有关更多说明,请检查意图示例中的可串行对象

于 2013-11-08T13:25:36.047 回答
0

而是使用:

public void updateList() {

    TextView infoz = (TextView) getView().findViewById(R.id.infoz);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String title = (String) extras.getSerializable("title");
于 2013-11-08T12:41:50.433 回答