在android中将数据从活动传递到dialogFragment
这是我将数据从活动发送到对话框片段的方法在android中将数据从活动传递到dialogFragment,android,arguments,parameter-passing,android-dialogfragment,Android,Arguments,Parameter Passing,Android Dialogfragment,这是我将数据从活动发送到对话框片段的方法 MultipleColorFragment multipleColorFragment = new MultipleColorFragment();//Get Fragment Instance Bundle data = new Bundle();//Use bundle to pass data for(int i = 0;i<product_data_two.getColor().size();i++) { data.putSt
MultipleColorFragment multipleColorFragment = new MultipleColorFragment();//Get Fragment Instance
Bundle data = new Bundle();//Use bundle to pass data
for(int i = 0;i<product_data_two.getColor().size();i++) {
data.putStringArrayList(i + "", product_data_two.getColor().get(i));
Log.d(TAG + " send fragment data",data.toString());
}
data.putInt("size", product_data_two.getColor().size());
multipleColorFragment.setArguments(data);//Finally set argument bundle to fragment
final FragmentManager fm=getFragmentManager();
multipleColorFragment.show(fm,"Color Set");
MultipleColorFragment MultipleColorFragment=新的MultipleColorFragment()//获取片段实例
Bundle data=新Bundle()//使用bundle传递数据
for(int i=0;iSinceproduct\u data\u two.getColor()
返回一个ArrayList首先在一个单独的ArrayList中添加颜色,然后将其全部放入要传递给片段的包中
MultipleColorFragment multipleColorFragment = new
MultipleColorFragment();//Get Fragment Instance
Bundle data = new Bundle();//Use bundle to pass data
ArrayList<String> colorArray = new ArrayList<>()
for(int i = 0; i<product_data_two.getColor().size(); i++) {
colorArray.add(product_data_two.getColor().get(i));
}
data.putStringArrayList("colorArray", colorArray);
data.putInt("size", product_data_two.getColor().size());
multipleColorFragment.setArguments(data);//Finally set argument bundle to fragment
final FragmentManager fm=getFragmentManager();
multipleColorFragment.show(fm,"Color Set");
MultipleColorFragment MultipleColorFragment=新建
MultipleColorFragment();//获取片段实例
Bundle data=new Bundle();//使用Bundle传递数据
ArrayList colorArray=新的ArrayList()
对于(int i=0;i)从product\u data\u two.getColor()
返回的列表类型是什么?发布您的product\u data\u two类及其子类(如果有)。在->getArguments().getStringArrayList(i+“”)中您得到了什么;Null??请阅读以下内容:&,以增加获得问题答案的机会!D/MultipleColorFragment颜色集大小:0(来自我的日志猫)@Aishwarya Tiwari Yes.java.lang.NullPointerException:尝试调用虚拟方法'boolean java.util.ArrayList.add(java.lang.Object)'在空对象引用上是的,我也建议这样做。我仍然会遇到此错误。请尝试在空对象引用上调用虚拟方法'java.lang.String java.util.ArrayList.toString()'。对不起。这一次是我的输入错误。非常感谢。
public class ProductTypeTwo {
private String productName;
private String brandID;
private String description;
private String productImage;
private Long colorNo;
private String category;
private String uid;
private ArrayList<ArrayList<String>> color;
public ProductTypeTwo(String productName, String brandID, String description, String productImage, Long colorNo, String category, String uid, ArrayList<ArrayList<String>> color) {
this.productName = productName;
this.brandID = brandID;
this.description = description;
this.productImage = productImage;
this.colorNo = colorNo;
this.category = category;
this.uid = uid;
this.color = color;
}
public ProductTypeTwo()
{
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getBrandID() {
return brandID;
}
public void setBrandID(String brandID) {
this.brandID = brandID;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getProductImage() {
return productImage;
}
public void setProductImage(String productImage) {
this.productImage = productImage;
}
public Long getColorNo() {
return colorNo;
}
public void setColorNo(Long colorNo) {
this.colorNo = colorNo;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public ArrayList<ArrayList<String>> getColor() {
return color;
}
public void setColor(ArrayList<ArrayList<String>> color) {
this.color = color;
}
}
bundle.putSerializable("SOME_KEY",product_data_two.getColor());
getArgument = (ArrayList<ArrayList<String>>) bundle.getSerializable("SOME_KEY");
MultipleColorFragment multipleColorFragment = new
MultipleColorFragment();//Get Fragment Instance
Bundle data = new Bundle();//Use bundle to pass data
ArrayList<String> colorArray = new ArrayList<>()
for(int i = 0; i<product_data_two.getColor().size(); i++) {
colorArray.add(product_data_two.getColor().get(i));
}
data.putStringArrayList("colorArray", colorArray);
data.putInt("size", product_data_two.getColor().size());
multipleColorFragment.setArguments(data);//Finally set argument bundle to fragment
final FragmentManager fm=getFragmentManager();
multipleColorFragment.show(fm,"Color Set");
ArrayList<String> colorArray =getArguments().getStringArrayList("colorArray");