我正在尝试开发更新表单。我在展示性别的微调值方面遇到问题。在我的MySql数据库中,性别的值是男性。现在,我必须在我的微调器中显示该值。如何从MySql数据库检索微调器数据的值
下面是编辑患者的代码。
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);
我已经在我的XML。我的问题是,我必须从数据库中检索该性别微调器的值并将其显示在微调器中。例如,用户注册了他的名字:艾伦和性别:男性。现在我想在我的EditPatient中检索该微调器(它是男性)的值。我怎样才能做到这一点? – user3226149