@Override public DownloadStreamTask(Context _c) { mContext = new WeakReference<Context>(_c); // dialog = new ProgressDialog(myact.this); text1 = (TextView) findViewById(R.id.textView1); Button cancelbtn = (Button) findViewById(R.id.ButtonCancel); cancelbtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Do something in response to button click cancel(true); } }); cancelbtn.setEnabled(true); }