gpt4 book ai didi

java - 如何在 "Map"中添加两个以上的字符串?我想加5个

转载 作者:行者123 更新时间:2023-11-29 21:42:42 25 4
gpt4 key购买 nike

我正在进行注册和登录,我希望它将更多内容添加到数据库中。例如名字、姓氏、电子邮件、用户名和密码。这是我的 register.java 代码:

public class Register extends Activity {

private Button bRR;

EditText etFN, etLN, etEmail, etUN, etPW, etRPW;
Spinner SMonth, SDay, SYaer;
TextView TVterms;
ArrayAdapter<CharSequence> adapter;
ProgressDialog PD;
String url = "http://10.0.0.12/accounts_java.php";
String fname , lname , uname , email , pass;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initTypeface();

//Button's go here
bRR = (Button)findViewById(R.id.bRR);

bRR = (Button)findViewById(R.id.bRR);
bRR.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf"));
//EditText's go here
etFN = (EditText)findViewById(R.id.etFN);
etLN = (EditText)findViewById(R.id.etLN);
etEmail = (EditText)findViewById(R.id.etEmail);
etUN = (EditText)findViewById(R.id.etUN);
etPW = (EditText)findViewById(R.id.etPW);
etRPW = (EditText)findViewById(R.id.etRPW);
//Spinner's go here
SMonth = (Spinner)findViewById(R.id.SMonth);
SDay = (Spinner)findViewById(R.id.SDay);
SYaer = (Spinner)findViewById(R.id.SYear);

SMonth = (Spinner)findViewById(R.id.SMonth);
adapter = ArrayAdapter.createFromResource(this, R.array.Month, R.layout.support_simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
SMonth.setAdapter(adapter);

SDay = (Spinner)findViewById(R.id.SDay);
adapter = ArrayAdapter.createFromResource(this, R.array.Day, R.layout.support_simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
SDay.setAdapter(adapter);

SYaer = (Spinner)findViewById(R.id.SYear);
adapter = ArrayAdapter.createFromResource(this, R.array.Year, R.layout.support_simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
SYaer.setAdapter(adapter);
//TextView's go here
TVterms = (TextView)findViewById(R.id.TVterms);
//oonClick's go here
//pd'// STOPSHIP: 12/18/2015
PD = new ProgressDialog(this);
PD.setMessage("Creating your account...");
PD.setCancelable(false);
}



public void onSignUpClick(View v)
{
if (v.getId() == R.id.bRR);
{
EditText fname = (EditText)findViewById(R.id.etFN);
EditText lname = (EditText)findViewById(R.id.etLN);
EditText uname = (EditText)findViewById(R.id.etUN);
EditText email = (EditText)findViewById(R.id.etEmail);
EditText pass1 = (EditText)findViewById(R.id.etPW);
EditText pass2 = (EditText)findViewById(R.id.etRPW);

String fnamestr = fname.getText().toString();
String lnamestr = lname.getText().toString();
String unamestr = uname.getText().toString();
String emailstr = email.getText().toString();
String pass1str = pass1.getText().toString();
String pass2str = pass2.getText().toString();

if (!pass1str.equals(pass2str))
{
//popup msg
Toast pass = Toast.makeText(Register.this, "Password do not match!", Toast.LENGTH_SHORT);
pass.show();

}

}
}

private void initTypeface() {

Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
TextView tittleText=(TextView) findViewById(R.id.textView5);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView7);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView8);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView9);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView10);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView11);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView12);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.textView13);
tittleText.setTypeface(myTypeface);

myTypeface = Typeface.createFromAsset(getAssets(), "fonts/SinkinSans-300Light.otf");
tittleText = (TextView) findViewById(R.id.TVterms);
tittleText.setTypeface(myTypeface);
}

public void insert(View view){

PD.show();
fname = etFN.getText().toString();
lname = etLN.getText().toString();
uname = etUN.getText().toString();
email = etEmail.getText().toString();
pass = etPW.getText().toString();

StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
PD.dismiss();
etFN.setText("");
etLN.setText("");
etUN.setText("");
etEmail.setText("");
etPW.setText("");
Toast.makeText(getApplicationContext(),
"Your account is created!",
Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
PD.dismiss();
Toast.makeText(getApplicationContext(),
"Error creating your account!",
Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams() {
Map<String,String> params = new HashMap<String,String>();
params.put("fname",fname);

return params;
}
};
MyApplication.getInstance().addToReqQueue(postRequest);
}

}

我想在 MySQL 中再添加 5 个值,而不仅仅是一个。

最佳答案

        @Override
protected Map<String,String> getParams() {
Map<String,String> params = new HashMap<String,String>();
params.put("fname",fname);
params.put("lname",lname );
...
return params;
}

关于java - 如何在 "Map"中添加两个以上的字符串?我想加5个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34367849/

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