sisko
sisko

Reputation: 9900

List namevaluepair elements

I am developing an Android project and I have the following code segments which collects information into an "array":

//setup array containing submitted form data
ArrayList<NameValuePair> data = new ArrayList<NameValuePair>();
data.add( new BasicNameValuePair("name", formName.getText().toString()) );
data.add( new BasicNameValuePair("test", "testing!") );


//send form data to CakeConnection
AsyncConnection connection = new AsyncConnection();
connection.execute(data);

My problem is how to read the individual members of that data list in my AsyncConnection class?

Upvotes: 5

Views: 7427

Answers (1)

MH.
MH.

Reputation: 45493

You should simply iterate over the list to get access to each NameValuePair. With the getName() and getValue() methods you can retrieve the individual parameters of every pair.

for (NameValuePair nvp : data) {
    String name = nvp.getName();
    String value = nvp.getValue();
}

Upvotes: 16

Related Questions