0

In a xml, I am having LinearLayout. Inside that I am using an ExpandableListView. Every expand item contain just one view which is a GridView. A GridView cell compose with three UI components which are ImageView, TextView and a Button. How I have got control about those three UI components is as follow,

public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater layoutInflater = (LayoutInflater) imageAdapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.single_grid_item, null);
        viewHolder = new ViewHolder();
        viewHolder.singleImageView = (ImageView) convertView.findViewById(R.id.singleGridItem_imageView);
        viewHolder.singleTextView = (TextView) convertView.findViewById(R.id.singleGridItem_textView);
        viewHolder.singleDownloadButton = (Button) convertView.findViewById(R.id.singleGridItem_download_button);
    }
}

// ViewHolder is a static nested inner class

Things are working prety fine. That means each cell identify as different cells. They have different images, and appropriate TextView labels and also Button click event also working fine. For the button click I have used a downloading with a ProgressDialog. That also working fine. What I want is disable the Button when the downloading in progress. Downloading happening in a seperate AsyncTask class. Please tell me how can I disable the button which user has clicked for downloading.

AnujAroshA
  • 4,623
  • 8
  • 56
  • 99

2 Answers2

0

set the click able property of the button to false in the on click method and enable it on post execute -- (view v) then set the property of v

Athul Harikumar
  • 2,501
  • 18
  • 16
0

Most of the time I have to wrte the answer for my own question. This one also the same. I have figure out the way. I have override the button click event in the getView() method as follow.

viewHolder.singleDownloadButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        // Some code goes here...

        new DownloadZipAsyncTask(imageAdapterContext, view).execute(zipFileUrl);

    }
});

By the time I click the Download button, I am passing the button view to the DownloadZipAsyncTask class. In that class, I am again creating Button instance and set the view invisible as follow in onProgressUpdate()

Button mybutton = (Button) view.findViewById(R.id.singleGridItem_download_button);
mybutton.setVisibility(View.INVISIBLE);

For button, it is working. But I can't change the ImageView or the TextView like that. Because in the click event, we only pass the Button view only. Therefore I am again in a problem with how to update a progress bar like that. Again, ProgressDialog is not a problem, only the ProgressBar UI component give the problem.

AnujAroshA
  • 4,623
  • 8
  • 56
  • 99