In my app i am having spinner inside the dialog box when user selects the value from the spinner it will goes to the asynctask
and executed for that i am using onItemClickListener
. But here the asynctask
was executing continuously at the dialog popup time and at the time of the user selecting the spinner value also i debug it and i understood that it was going to the onItemclickListener
at the starting and checking the values inside public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {});
But i need to start the asynctask
only when user selects the spinner values can any one tell me how to achieve this.
NOTE:Here this code i am using inside adapter which was using for list view.
This is my code inside on onItemclickListener
leaves_type.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// leaves_type_string = leaves_type.getSelectedItem().toString();
new update_leave_entry_breakup_values().execute("UpdateValues",
"1082", id_string, leaves_type.getSelectedItem().toString(), username, "",
"", "", "", "", "", "");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
This is my asynctask
calling inside spinner
class update_leave_entry_breakup_values extends
AsyncTask<String, integer, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressdialog_view.setMessage("Updating leaves...");
progressdialog_view.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String TempMethod = params[0];
String Flag = params[1];
String value1 = params[2];
String value2 = params[3];
String value3 = params[4];
String value4 = params[5];
String value5 = params[6];
String value6 = params[7];
String value7 = params[8];
String value8 = params[9];
String value9 = params[10];
String value10 = params[11];
try {
SoapObject request = new SoapObject(NAME_SPACE, TempMethod);
request.addProperty("Flag", Flag);
request.addProperty("value1", value1);
request.addProperty("value2", value2);
request.addProperty("value3", value3);
request.addProperty("value4", value4);
request.addProperty("value5", value5);
request.addProperty("value6", value6);
request.addProperty("value7", value7);
request.addProperty("value8", value8);
request.addProperty("value9", value9);
request.addProperty("value10", value10);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE Android_HttpTransport = new HttpTransportSE(URL);
Android_HttpTransport.debug = true;
Android_HttpTransport.call(NAME_SPACE + TempMethod, envelope);
String responseXml = envelope.getResponse().toString();
return responseXml;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
progressdialog_view.dismiss();
if (result == null) {
Toast.makeText(context, "Error while reading data",
Toast.LENGTH_SHORT).show();
} else if (result.equals("0")) {
Toast.makeText(context, "Error while Updating data",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Update Success",
Toast.LENGTH_SHORT).show();
}
}
}