>我有 JSON 到可序列化的 claa,然后我用它来填充 listview,一切正常,但我想用一个可序列化对象填充另一个 XML 页面上的文本视图,我读到最好的方法是捆绑意图,但我确实编码错误。
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);
改用:
public void updateList() {
TextView infoz = (TextView) getView().findViewById(R.id.infoz);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String title = (String) extras.getSerializable("title");
如果你想传递任何原始数据类型值(String,int,long,float等),那么不需要使用Bundle.putExtra(KEY,Serialized Object)和Bundle.getSerializable(KEY)。您可以使用 Bundle.putExtra(KEY,基元数据);
如果要将类对象传递给意图/捆绑包,则需要在该类中实现可序列化/可解析,如下所示:
public class Test implements Serializable
{
private static final long serialVersionUID = 1L;
int test1;
}
然后,您可以将该对象实例传递给意图,例如:
myIntent.putExtra( KEY, new Test() );
有关更多说明,请检查在意图示例中传递可排列对象