- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 parceler实现 Parcelable 接口(interface)的库。
我有这样的模型
@Parcel(Parcel.Serialization.BEAN)
public class Ads {
private Long id;
private String title;
private String description;
private AdsType adsType;
private String phone;
private String email;
private String city;
private Long categoryId;
private ArrayList<Integer> creationDate;
//TODO remove transient
private transient ArrayList<Long> imageIds;
private transient Long price;
@SerializedName("adsCategory")
private AdvCategory advCategory;
public Ads() {}
public Ads(String title, String description, AdsType adsType, String
phone, String email, String city, Long categoryId, Long price, ArrayList<Long> imageIds) {
this.title = title;
this.description = description;
this.adsType = adsType;
this.phone = phone;
this.email = email;
this.city = city;
this.categoryId = categoryId;
this.price = price;
this.imageIds = imageIds;
}
@ParcelConstructor
public Ads(Long id, String title, String description, AdsType adsType,
String phone, String email, String city, ArrayList<Long>
imageIds, Long price, ArrayList<Integer> creationDate, AdvCategory advCategory) {
this.id = id;
this.title = title;
this.description = description;
this.adsType = adsType;
this.phone = phone;
this.email = email;
this.city = city;
this.imageIds = imageIds;
this.price = price;
this.creationDate = creationDate;
this.advCategory = advCategory;
}
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public AdsType getAdsType() {
return adsType;
}
public String getPhone() {
return phone;
}
public String getEmail() {
return email;
}
public String getCity() {
return city;
}
public AdvCategory getAdvCategory() {
return advCategory;
}
public void setAdvCategory(AdvCategory advCategory) {
this.advCategory = advCategory;
}
public Long getCategoryId() {
return categoryId;
}
public ArrayList<Long> getImageIds() {
return imageIds;
}
public void setImageIds(ArrayList<Long> imageIds) {
this.imageIds = imageIds;
}
public int getPrice() {
//TODO replace with real price
return new Random().nextInt(100000);
}
public void setPrice(Long price) {
this.price = price;
}
public ArrayList<Integer> getCreationDate() {
return creationDate;
}
public void setCreationDate(ArrayList<Integer> creationDate) {
this.creationDate = creationDate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ads ads = (Ads) o;
return id.equals(ads.id);
}
@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + title.hashCode();
result = 31 * result + description.hashCode();
result = 31 * result + adsType.hashCode();
result = 31 * result + (phone != null ? phone.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (city != null ? city.hashCode() : 0);
result = 31 * result + advCategory.hashCode();
result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Ads{" +
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", adsType=" + adsType +
", phone='" + phone + '\'' +
", email='" + email + '\'' +
", city='" + city + '\'' +
", creationDate='" + creationDate.toString() +
'}';
}
public static class List extends ArrayList<Ads> {}
}
我正在包装我的模型并将其放入 Intent 中。
Intent adsDetailsIntent = new Intent(this, AdsDetailsActivity.class);
Bundle details = new Bundle();
Ads advertisement = mAdsAdapter.getItem(position);
details.putParcelable(AdsDetailsActivity.ADS_DETAILS, Parcels.wrap(advertisement));
Ads ads = Parcels.unwrap(details.getParcelable(AdsDetailsActivity.ADS_DETAILS));
Log.d("ads", ads.toString());
adsDetailsIntent.putExtras(details);
startActivity(adsDetailsIntent);
在 Activity 中展开
mAdsDetails = Parcels.unwrap(
(Parcelable) this.getIntent().getParcelableExtra(ADS_DETAILS));
但有时字段“creationDate”在 Activity 中展开后有错误的值。
我尝试记录它,在从 Bundle 解包后 - 没问题,但在 Activity 中 - 它有奇怪的数据。
示例:
unwrap from bundle immediately after creating it
Ads{id=16, title='Mtitle', description='Mads', adsType=BUY, phone='+30890931231', email='+380932309046', city='Анабарский национальный улус', creationDate='[2015, 8, 8, 9, 27, 0, 350946000]}
unwrap from activity intent.getExtra()
Ads{id=null, title='null', description='null', adsType=null, phone='null', email='null', city='null', creationDate='[8, 8, 9, 27, 0, 350946000, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
我不知道为什么,但它正在创建一个带有 creationDate 1 的数组大小并用零填充。
最佳答案
我注意到在你打开类(class)的时候
mAdsDetails = Parcels.unwrap(
(Parcelable) this.getIntent().getParcelableExtra(ADS_DETAILS));
你试过这样吗:
mAdsDetails = Parcels.unwrap(this.getIntent().getExtras().get(ADS_DETAILS));
关于android - Parceler unwrap 提供错误的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893306/
func initializePickerViewProperties() { let font = UIFont (name: "SanFranciscoDisplay-Regular",
我试图将预先附加的字符串作为 URL 请求传递,但我不断收到错误消息: fatal error :在展开可选值时意外发现 nil 此错误指向行:let searchTerm = "http://goo
我有一个像这样的html结构 旁边的两个 div 确实有类和子元素,但为了这个问题,您不需要知道它们是什么。在 DOM 准备就绪后,我将两个内部 div 包裹在一个新的 div 中,就
显然是我的语法错误。 我有大量的 div,其中少量的内容包含在 anchor 中。我要做的是移除 anchor 。 感谢您的帮助! http://jsfiddle.net/danielredwood/
关闭。这个问题是 opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 已关闭 2 年前。 奥 git _
我已经包装了阶段,我想使用“wrap”函数来打开它们。但是,在这种情况下,由于我不清楚的原因,我无法获得展开的相位。 包裹的阶段是 通过观察横截面,我可以看到相被包裹 我已将图像从 0 缩放到 2*p
用 jQuery 包装 div 后,展开它们然后尝试再次包装它们似乎会丢失 float 属性(我的猜测),我不知道如何解决这个问题。 当第一次按下 JSFiddle 中的换行按钮时,它会像我期望的那样
我将容器 .vorteile 通过 jQuery 包装在 .vorteile_outer 中。当我想在 .vorteile 上使用 .unwrap() 删除 .vorteile_outer 时,.vo
这个问题已经有答案了: jQuery : remove element except inside element (4 个回答) 已关闭 9 年前。 jquery中有一个很棒的方法叫做wrap()它
这个问题已经有答案了: jQuery : remove element except inside element (4 个回答) 已关闭 9 年前。 我有一段 HTML 代码: table 我如何从
当用户提交或聚焦无效输入时,我有一个包含在错误 div 中的文本字段。如果用户纠正了错误,我想删除包装器,但是,unwrap() 方法会导致字段失去焦点。 $(special_input).live(
我正在寻找一种方法来“解开”已发布到 MVC 核心服务的 JSON。比方说,我有以下方法: [HttpPost] public dynamic SayHello(string First
我引用了以下网页: https://serverfault.com/questions/153983/sockets-found-by-lsof-but-not-by-netstat 使用Python
我有一个 jQuery 突出显示工具,它可以动态地将一个类添加到一个字符串中。如果一个元素包含单词 Hello World 并且用户搜索'ell',它为单词添加了一个跨度 Hello world 要重
如何在 Iframe 中展开 span 标签。 Directional 我尝试使用此删除 $('iframe').contents().find(".newtext").unwrap(); 如果 re
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
在我的代码中,我有很多带有 Option 的结构在他们里面。我需要在很多地方与他们一起工作,所以我的代码中充斥着像 car.engine.as_ref().unwrap() 这样的结构访问。 .这对代
这个问题在这里已经有了答案: Unable to read file contents to string - Result does not implement any method in sco
出于某种原因,Rust 编译器提示 Result 没有实现 unwrap,即使我提供的错误类型确实实现了 Debug。下面提供了出错的代码。 use std::fmt::{Display, Debug
多么奇怪的错误: use std::collections::BTreeMap; struct MyStruct1; struct Error; fn get_res() -> Result), Er
我是一名优秀的程序员,十分优秀!