Issue
My class ProductAdapter extends ArrayAdapter on getView i'm inflating rows with 2 buttons in the each row for (+) and (-) and set anonim OnClickListener for each button , like this :
viewHolder.removeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BigDecimal count = product.getCount().subtract(BigDecimal.ONE);
if (count.signum() < 0) count = BigDecimal.ZERO;
product.setCount(count);
viewHolder.countView.setText(formatValue(count, product.getUnit()));
mListener.onCardClick(v);
}
});
On activity i need to do some AsyncTask when i'm using integer value from each row. The problem is when AsyncTask executing user still can change product adapter(Buttons are working). I need to disable them while AsyncTask is working and then reenable after completing. I was trying to disable ListView with no luck. Also i was trying to override ArrayAdapter methods isAllEnadled and isEnabled also with no luck.
Solution
Interesting problem, you need a State and a place to save this, this State can be used to control the click behavior. You can save this either in the product itself or some other place like a list corresponding to that index
Something like
protected void onPreExecute(Void result) {
product.setFetching(true)
}
protected void onPostExecute(Void result) {
product.setFetching(false)
}
in onClick()
you can check same and return like this
if (product.isFetching())
return;
Answered By - Akhil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.