android - how to disable button in listview -
i new android development , having hard time wrapping head around android listviews
. pretty went through entire google search , tried every "possible" solution, without getting listview
, having hard time solving problem.
i want disable particular button when click complete_btn in listview
item.
right now, complete_btn.setonclicklistener
in else {}
part giving me null pointer exception (it's fine in if(converview == null)
part). if remove code, works fine, commenting out in listener not work.
i want disable button if yes clicked in alert dialog pops when button pressed! please me this??
public view getview(final int position, view convertview, final viewgroup parent) { view itemview; if (convertview == null) { itemview = layoutinflater.inflate(r.layout.activity_selected_delivery_item, parent, false); final deliveryltem deliveryltemposition = epiceriedelivery.selecteddeliveryitem.get(position); icon = (imageview) itemview.findviewbyid(r.id.selected_delivery_img); name = (textview) itemview.findviewbyid(r.id.selected_item_name); phone_tx = (textview) itemview.findviewbyid(r.id.selected_item_phone); complete_btn = (button) itemview.findviewbyid(r.id.selected_complete_btn); if(deliveryltemposition.order_taken_str.equals("2")){ complete_btn.setenabled(false); } phone_tx.settext(deliveryltemposition.recipient_phonenum); complete_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ((listview) parent).performitemclick(v, position , 0); try{ order_seq = deliveryltemposition.order_seq; position_sms = position; deliveryltem deliveryltemposition1 = epiceriedelivery.selecteddeliveryitem.get(position); string name = deliveryltemposition1.recipient_name; string phone = deliveryltemposition1.recipient_phonenum; alertdialog dialog = createdialogbox_finish(name, phone, position); dialog.show(); }catch (exception e){ } } }); return itemview; }else{ itemview = convertview; if(epiceriedelivery.selecteddeliveryitem.size() != 0){ final deliveryltem deliveryltemposition = epiceriedelivery.selecteddeliveryitem.get(position); name = (textview) itemview.findviewbyid(r.id.selected_item_name); phone_tx = (textview) itemview.findviewbyid(r.id.selected_item_phone); complete_btn = (button) itemview.findviewbyid(r.id.selected_complete_btn); if(deliveryltemposition.order_taken_str.equals("2")){ complete_btn.setenabled(false); } complete_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ((listview) parent).performitemclick(v, position , 0); try{ order_seq = deliveryltemposition.order_seq; position_sms = position; deliveryltem deliveryltemposition1 = epiceriedelivery.selecteddeliveryitem.get(position); string name = deliveryltemposition1.recipient_name; string phone = deliveryltemposition1.recipient_phonenum; buttons.add(complete_btn); alertdialog dialog = createdialogbox_finish(name, phone, position); dialog.show(); }catch (exception e){ } } }); } return convertview; }} private alertdialog createdialogbox_finish(string name, string phone, int position1){ final string name_str = name; final string phone_str = phone; courier_id = selectedactivity2.courier_id; int button_pos = position1; final string message_finish = "message_content"; buttons.get(0).setenabled(false); buttons.clear(); alertdialog.builder builder = new alertdialog.builder(getcontext()); builder.setmessage("배송을 완료하셨습니까?"); builder.setpositivebutton("yes", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { try{ smsmanager smsmanager = smsmanager.getdefault(); if (message_finish.length() > 60) { arraylist<string> contents = smsmanager.dividemessage(message_finish); for(int j = 0; j<contents.size(); j++){ smsmanager.sendtextmessage(phone_str, null, contents.get(j), null, null); } } else { smsmanager.sendtextmessage(phone_str, null, message_finish, null, null); } }catch (exception e){ } } }); builder.setnegativebutton("no", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); alertdialog dialog = builder.create(); return dialog; }
add
button button = dialog.getbutton(alertdialog.button_positive); button.setenabled(false);
inside
builder.setpositivebutton("yes", new dialoginterface.onclicklistener() { }
method :
builder.setpositivebutton("yes", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { button button = dialog.getbutton(alertdialog.button_positive); button.setenabled(false); try{ smsmanager smsmanager = smsmanager.getdefault(); if (message_finish.length() > 60) { arraylist<string> contents = smsmanager.dividemessage(message_finish); for(int j = 0; j<contents.size(); j++){ smsmanager.sendtextmessage(phone_str, null, contents.get(j), null, null); } } else { smsmanager.sendtextmessage(phone_str, null, message_finish, null, null); } }catch (exception e){ } } });
Comments
Post a Comment