1

我想拆分 mProductType 是一个列表,而 mRetailerid 是另一个列表。我怎样才能得到它????

public class RetailerNames implements Serializable{


private String mProductType;
private String mRetailerid;

public String getmProductType() {
    return mProductType;
}

public void setmProductType(String mProductType) {
    this.mProductType = mProductType;
}

public String getmRetailerid() {
    return mRetailerid;
}

public void setmRetailerid(String mRetailerid) {
    this.mRetailerid = mRetailerid;
}
@Override
   public String toString() {
    return   mProductType + "," +
            mRetailerid ;  

}

我使用了以下代码:

    ArrayList<RetailerNames> retailerNamesList = (ArrayList<RetailerNames>) getIntent().getExtras().getSerializable("ProductsDetailsDescriptionPage");
    System.out.println("The retailer details are"+" "+retailerNamesList);

现在我当前的输出是:

零售商详细信息是 [Krish,48, Danesh,47]

但我想得到一个像 [Krish,Danesh] 这样的列表。而 [48,47] 是另一个列表。我该怎么办?

请给我解决方案???

请给我一个将数组列表拆分为单独列表的想法???

4

4 回答 4

3
  ArrayList list = new ArrayList();

 Iterator<RetailerNames > retaileriterator = retailerNamesList.iterator();

while(retaileriterator.hasNext()){
 id=retaileriterator .next().getmRetailerid();
 System.out.println(id);
  list.add(id);
   }
 System.out.println(list);
于 2013-09-04T11:50:08.203 回答
1
In my condition getLocationDetails return arraylist
and  LocationDetails is POJO same like your class RetailerNames 
Iterator<LocationDetails> it= getUserLocationsWrapper.getLocationDetails().iterator();
while(locationCitiDetailsItr.hasNext()){
locationCitiDetailsItr.next().getCity());
}
same i think  try this one
Iterator<RetailerNames > retaileriterator = retailerNamesList.iterator();
while(retaileriterator.hasNext()){
Object id=retaileriterator .next().getmRetailerid();
//add this id into another list
//same RetailerNames
}
于 2013-09-04T09:25:38.500 回答
0

使用嵌套数组

将 [Krish,48] 放在一个列表中,将 [damesh,47] 放在另一个列表中,并将两个列表放在一个主数组列表中

于 2013-09-04T04:57:53.177 回答
0

像这样使用

   public class RetailerNames implements Serializable{


    private String mProductType;
    private String mRetailerid;

    public String getmProductType() {
        return mProductType;
    }

    public void setmProductType(String mProductType) {
        this.mProductType = mProductType;
    }

    public String getmRetailerid() {
        return mRetailerid;
    }

    public void setmRetailerid(String mRetailerid) {
        this.mRetailerid = mRetailerid;
    }
    @Override
    public String toString() {
        return  + mProductType + ","
                + mRetailerid +;  //Remove "[" this..
    }

和,

 ArrayList<RetailerNames> retailerNamesList = (ArrayList<RetailerNames>) getIntent().getExtras().getSerializable("ProductsDetailsDescriptionPage");
        System.out.println("The retailer details are"+" "+retailerNamesList);

现在试试

Object temp[]=retailerNamesList.toArray();
String[] values=temp.toString().split(",");

String names=values[0];
String names=values[1];
于 2013-09-04T06:11:36.970 回答