【问题标题】:List namevaluepair elements列出名称值对元素
【发布时间】:2012-06-07 14:43:22
【问题描述】:

我正在开发一个 Android 项目,我有以下代码段将信息收集到一个“数组”中:

//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);

我的问题是如何在我的 AsyncConnection 类中读取该数据列表的各个成员?

【问题讨论】:

    标签: android list foreach


    【解决方案1】:

    您应该简单地遍历列表以访问每个NameValuePair。使用getName()getValue() 方法,您可以检索每对的各个参数。

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

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 1970-01-01
      • 2014-04-09
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      相关资源
      最近更新 更多