我有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);
答案 0 :(得分: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");
答案 1 :(得分:0)
如果要传递任何原始数据类型的值(String,int,long,float等),则不需要使用Bundle.putExtra(KEY,Serialized Object)和Bundle.getSerializable(KEY)。您可以使用Bundle.putExtra(KEY,原始数据);
如果要将类对象传递给intent / bundle,则需要在该类中实现Serializable / Parsable,如:
public class Test implements Serializable
{
private static final long serialVersionUID = 1L;
int test1;
}
然后您可以将该对象实例传递给intent:
myIntent.putExtra( KEY, new Test() );
有关更多说明,请检查pass seriable object in intent example