If you have to use NameValuePair
, there are two possible solutions.
You can convert a Map
to a List
of NameValuePair
:
List<NameValuePair> convertParameters(Map<String, Double> parameters) {
List<NameValuePair> result = new ArrayList<NameValuePair>();
for (Entry<String, Double> entry : parameters.entrySet()) {
result.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
}
return result;
}
Or you can implement a new NameValuePair to handle Double values:
public class DoubleNameValuePair implements NameValuePair {
String name;
double value;
public DoubleNameValuePair(String name, double value) {
this.name = name;
this.value = value;
}
@Override
public String getName() {
return name;
}
@Override
public String getValue() {
return Double.toString(value);
}
}
In the latter case, you can use a List of NameValuePair that can be passed directly to UrlEncodedFormEntity's constructor:
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new DoubleNameValuePair("lat", 1.0));
parameters.add(new DoubleNameValuePair("lng", 2.0));