我想将ArrayList<NameValuePair> nameValuePairs
个活动传递给另一个活动。我为此写了parcelable class
。
Parcelable Class:
/**Getters/Setters have been removed to make reading easier*//
public class BasicNameValuePair implements Parcelable {
private String name;
private String value;
public BasicNameValuePair(String name, String value){
this.name = name;
this.value = value;
}
protected BasicNameValuePair(Parcel in) {
name = in.readString();
value = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(value);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<BasicNameValuePair> CREATOR = new Creator<BasicNameValuePair>() {
@Override
public BasicNameValuePair createFromParcel(Parcel in) {
return new BasicNameValuePair(in);
}
@Override
public BasicNameValuePair[] newArray(int size) {
return new BasicNameValuePair[size];
}
};
}
我发送数据的第一个活动:
ArrayList<com.example.ss.myapplication.BasicNameValuePair> nameValuePairs;
nameValuePairs = new ArrayList<com.example.ss.myapplication.BasicNameValuePair>();
nameValuePairs.add(new com.example.ss.myapplication.BasicNameValuePair("name",value));
nameValuePairs.add(new com.example.ss.myapplication.BasicNameValuePair("name1", value1));
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putParcelableArrayListExtra("extraextra", nameValuePairs);
startActivity(intent);
在我的第二个获得nameValuePair
的活动中 ArrayList<com.example.ss.myapplication.BasicNameValuePair> testing = this.getIntent().getParcelableArrayListExtra("extraextra");
for (com.example.ss.myapplication.BasicNameValuePair n : testing) {
String name = n.getName();
String value = n.getValue();
System.out.print("name" + name + "value:" + value);
}
但是,当我想添加数据nameValuePairs时,我收到错误。
BasicNameValuePair(android.os.Parcel) in BasicNameValuePair cannot be applied to (java.lang.String, java.lang.String)
我应该如何更改BasicNameValuePair类?
答案 0 :(得分:0)
中没有
getname
和getvalue
public class BasicNameValuePair implements Parcelable {
private String name;
private String value;
public String getName() {
return name;
}
public String getValue() {
return value;
}
********************* etc*****************
}