开发者

Stopping a button being pressed whilst work being performed

I have a button on an activity which when pressed loops through a list of items, adds them to a database and then closes the activity.

My problem is that sometimes on slow phones and a lot of list items the user can press the button again before the activity closes, causing a duplicate insertion.

What is the recommended way of stopping this from happening, I've tried disabling the button on press but it does not get refreshed on the screen.

buttonAddChecked.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            SparseBooleanArray CheckedItemIDs = listViewFavorites.getCheckedItemPositions();

            for (int i = 0; i < CheckedItemIDs.size(); i++) {

                View element = listViewFavorites.getAdapter().getView(CheckedItemIDs.keyAt(i),
                   开发者_StackOverflow中文版     null, null);

                ShoppingListItem sli;
                sli = (ShoppingListItem) element.getTag();

                db.insertItem(sli.itemName, 0, sli.itemNotes,
                        sli.categoryID);
            } // looped round all checked items

            finish();
        }
    });


use progressDialog

to stop user interaction once it presses the button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜