gpt4 book ai didi

android - 如何从 MySql 数据库检索微调器数据的值

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

我正在尝试开发更新表单。我在显示性别微调器的值时遇到问题。在我的 MySql 数据库中,性别值为 Male。现在我必须在微调器中显示该值。

这是编辑患者的代码。

        ArrayAdapter adapter = ArrayAdapter.createFromResource(
this, R.array.gender_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown

_item);


protected String doInBackground(String... params) {

// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("uid", uid));

// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_patient_detials, "GET", params);

// check your log for json response
Log.d("Single Patient Details", json.toString());

// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_PATIENT); // JSON Array

// get first product object from JSON Array
JSONObject product = productObj.getJSONObject(0);

// product with this pid found
// Edit Text
inputusername= (EditText) findViewById(R.id.username);
inputpassword = (EditText) findViewById(R.id.password);
inputfname= (EditText) findViewById(R.id.fname);
inputlname = (EditText) findViewById(R.id.lname);
inputcontact = (EditText) findViewById(R.id.contacts);
inputaddress = (EditText) findViewById(R.id.address);
inputdate = (TextView) findViewById(R.id.datetext);//bday
inputgender = (Spinner) findViewById(R.id.gender);
inputage = (TextView) findViewById(R.id.number);
//rdmale = (RadioButton) findViewById(R.id.rdmale);
//rdfemale = (RadioButton) findViewById(R.id.rdfemale);




// display product data in EditText
inputusername.setText(product.getString(TAG_USERNAME));
inputpassword.setText(product.getString(TAG_PASSWORD));
inputfname.setText(product.getString(TAG_FNAME));
inputlname.setText(product.getString(TAG_LNAME));
inputcontact.setText(product.getString(TAG_CONTACT));
inputaddress.setText(product.getString(TAG_ADDRESS));
inputgender.setSelectedItem(product.getString(TAG_GENDER));//it's an error here. help me //how to set value for spinner
inputage.setText(product.getString(TAG_AGE));
inputdate.setText(product.getString(TAG_BIRTHDAY));
}else{
// product with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});

return null;
}


/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}

/**
* Background Async Task to Save product Details
* */
class SaveProductDetails extends AsyncTask<String, String, String> {

/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EditPatientActivity.this);
pDialog.setMessage("Saving patient ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

/**
* Saving product
* */
protected String doInBackground(String... args) {

// getting updated data from EditTexts
String username = inputusername.getText().toString();
String password = inputpassword.getText().toString();
String fname = inputfname.getText().toString();
String lname = inputlname.getText().toString();
String contact = inputcontact.getText().toString();
String age = inputage.getText().toString();
String address = inputaddress.getText().toString();
//String birthday = inputbirthday.getText().toString();
String gender = inputgender.getSelectedItem().toString();
String bday = inputdate.getText().toString();

// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
//params.add(new BasicNameValuePair(TAG_PID, pid));
params.add(new BasicNameValuePair(TAG_USERNAME, username));
params.add(new BasicNameValuePair(TAG_PASSWORD, password));
params.add(new BasicNameValuePair(TAG_FNAME, fname));
params.add(new BasicNameValuePair(TAG_LNAME, lname));
params.add(new BasicNameValuePair(TAG_ADDRESS, address));
params.add(new BasicNameValuePair(TAG_BIRTHDAY, bday));
params.add(new BasicNameValuePair(TAG_AGE, age));
params.add(new BasicNameValuePair(TAG_GENDER, gender));
params.add(new BasicNameValuePair(TAG_CONTACT, contact));



// sending modified data through http request
// Notice that update product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_update_patient,
"POST", params);

// check json success tag
try {
int success = json.getInt(TAG_SUCCESS);

if (success == 1) {
// successfully updated
Intent i = getIntent();
// send result code 100 to notify about product update
setResult(100, i);
finish();
} else {
// failed to update product
}
} catch (JSONException e) {
e.printStackTrace();
}

return null;
}


/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product uupdated
pDialog.dismiss();
}
}

inputgender.setAdapter(adapter);

最佳答案

您必须在 string.xml 文件中声明一个字符串数组

<string-array name="gender">
<item>Male</item>
<item>Female</item>
</string-array>

从数据库检索数据后

if(gender.equalsIgnoreCase("male"){
youeSpinner.setSelection(0);
}
else if(gender.equalsIgnoreCase("female"){
youeSpinner.setSelection(1);
}

关于android - 如何从 MySql 数据库检索微调器数据的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641719/

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