gpt4 book ai didi

java - 如何将 2 个或多个值放入 ArrayList

转载 作者:行者123 更新时间:2023-12-01 13:47:09 25 4
gpt4 key购买 nike

我想知道如何将多个值放入 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();
}
}
}
}

最佳答案

支持哥们吗?在这种情况下,只需使用 params 的 add 函数即可。不强制使用特定大小进行初始化。

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Key1", "Value1"));
params.add(new BasicNameValuePair("Key2", "Value"));

你将会得到这样的东西

键1 = 值1;键2 = 值

希望有效果

关于java - 如何将 2 个或多个值放入 ArrayList<NameValuePair>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20277326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com