lakshman lakshman - 1 year ago 88
Android Question

How to disable click events checking of button at the starting of activity in android

I am creating one list view with text and buttons in that list view data was populated from async task and here i am displaying that list view with in dialog like this enter image description here. My problem is When the user selects the "spinner" value present in the list view and at the dialog popup time the async task i wrote inside

of the spinner was executing continuously displaying like this

enter image description here.Please help me with this and sorry for asking question like this.This is my adapter code to execute clicking cancel button

leaves_type.setOnItemSelectedListener(new OnItemSelectedListener() {

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, "",
"", "", "", "", "", "");


public void onNothingSelected(AdapterView<?> parent) {


This is my async task:

class update_leave_entry_breakup_values extends
AsyncTask<String, integer, String> {

protected void onPreExecute() {
// TODO Auto-generated method stub

progressdialog_view.setMessage("Updating leaves...");;


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(
envelope.dotNet = true;
HttpTransportSE Android_HttpTransport = new HttpTransportSE(URL);
Android_HttpTransport.debug = true; + TempMethod, envelope);
String responseXml = envelope.getResponse().toString();
return responseXml;
} catch (Exception ex) {

return null;

protected void onPostExecute(String result) {
// TODO Auto-generated method stub


if (result == null) {
Toast.makeText(context, "Error while reading data",
} else if (result.equals("0")) {
Toast.makeText(context, "Error while Updating data",
} else {
Toast.makeText(context, "Update Success",


Answer Source

Remove notifyDataSetChanged(); from your click event,

final Button cancel = (Button) row.findViewById(;
        cancel.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                int tag_position = (Integer) v.getTag();
                notifyDataSetChanged(); // remove this
                new cancel_leave_entry_breakup_values().execute("UpdateValues", "1083",
                        leave_app.getID(), leave_app.getUsername().toString(),
                        "", "", "", "", "", "", "", "");


According to me you are calling your adapter two times. you need to call it once.

Use notifyDataSetChanged(); when you want to refresh data of listview like OnRestart() method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download