Я пытаюсь разработать форму обновления. У меня проблема с отображением значения счетчика для пола. В моей базе данных MySql значение пола - мужчина. Теперь я должен показать это значение в своем счетчике.Как получить значение данных spinner из базы данных 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. моя проблема в том, что мне нужно получить значение этого гендерного счетчика из базы данных и отобразить его в spinner. Например, пользователь зарегистрировал свое имя: allan и gender: male. Теперь я хочу получить значение этого счетчика (который есть Мужской) в моем EditPatient. Как я могу это сделать? – user3226149