我想知道如何将多个值放入ArrayList<NameValuePair>
。这是我的代码,但它不起作用。有人帮我解释ArraysList<NameValuePair>
。
这是我的代码:
public void OnClickForSave(View v) throws Exception {
String st = null;
String str = null;
String response = null;
String memberID = "000000007";
String teamID = "000007";
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("userID", memberID));
postParameters.add(new BasicNameValuePair("teamID", teamID));
if (v.getId() == (R.id.imgbtn_layout2)) {
Intent intent = new Intent(this, IntentTesting.class);
startActivity(intent);
}
if (v.getId() == (R.id.imgbtn_lsave)) {
if (txt_teamID.getText().toString().trim().equals(null)
|| txt_teamID.getText().toString().trim().equals("")) {
AlertDialog empty = createDialogEmpty(this, "Enter Team ID");
empty.show();
txt_teamID.selectAll();
txt_teamID.requestFocus();
}
else if (txt_teamID.getText().toString().trim().length() > 6) {
AlertDialog notFormat = createDialogEmpty(this, "More Than 6 Characters");
txt_teamID.selectAll();
txt_teamID.requestFocus();
notFormat.show();
} else {
try {
st = CustomHttpClient.executeHttpGet("http://192.168.200.14/football365/DBConnection.php");
str = CustomHttpClient.executeHttpGet("http://192.168.200.14/football365/responseJson.php");
response = CustomHttpClient.executeHttpPost("http://192.168.200.14/football/joinTeam.php",
postParameters);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
答案 0 :(得分:1)
Sup哥们? 在这种情况下,只需使用params的add函数。使用特定大小进行初始化并非强制要求。
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Key1", "Value1"));
params.add(new BasicNameValuePair("Key2", "Value"));
你会有这样的东西
Key1 = Value1; Key2 =值
希望它有效
答案 1 :(得分:0)
ArrayList<BasicNameValuePair> postParameters = new ArrayList<BasicNameValuePair>();
您需要使用列表将存储的数据类型初始化ArrayLists。
在此之后使用:
ArrayList.add(element e);
您可以根据需要多次调用此方法。
答案 2 :(得分:0)
尝试下面的代码
List<NameValuePair> postParameters = new ArrayList<NameValuePair>(2);
postParameters.add(new BasicNameValuePair("userID",memberID));
postParameters.add(new BasicNameValuePair("teamID",teamID));
它对我有用。