onclicklistener - How to get out from onClick method for Button Listener in Android -
consider following code:
button add_product_button = (button) findviewbyid(r.id.add_product_button); add_product_button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { //before going further, check whether information provided or not edittext item_title_text = (edittext) findviewbyid(r.id.item_title); if(isempty(item_title_text)){ break; }
i want 'break;' response not want proceed further (not executing rest code , out).
this alarm user insufficient information has been provided. how can achieve this?
i recommend disabling button if required information not there user isn't able click it. display message on whatever dialog/view inform user information required, or add string "(required)" after edittext hint.
button add_product_button = (button) findviewbyid(r.id.add_product_button); edittext item_title_text = (edittext) findviewbyid(r.id.item_title); if(isempty(item_title_text)){ add_product_button.setenabled(false); }
however, if need way described reason, answer how "get out", need return
out of onclick method.
if(isempty(item_title_text)){ return; }
before returning call method whatever want (your own method perhaps displays message user have not enough information).
if(isempty(item_title_text)){ notifyuserofemptyfield(); return; }
Comments
Post a Comment