android - How to display changed state of checkbox before other code executes in OnCheckedChangeListener.onCheckedChanged -
i need add new view after clicking on checkbox. , want show changed state of checkbox , display new view, when click on checkbox, ui stops second or few, , @ same time showing new view , checkbox displaying checked.
my code simple
{ checkbox = (checkbox) findviewbyid(r.id.select_param_value_checkbox); if (checkbox != null) { checkbox.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { oncheckboxchanged(ischecked); } }); } } protected void oncheckboxchanged(boolean ischecked) { //this listener adding in constructor , creates in view want add child on_change_listener.onfilterparamvaluechanged(this); }
and code listener is:
public void onfilterparamvaluechanged(myclass obj) { addview(new myview(getcontext(), obj.gettitle())); }
code of myview:
class myview extends linearlayout{ private textview title; public myview(context context, string text) { super(context); viewgroup.inflate(context, r.layout.my_view, this); title = (textview) findviewbyid(r.id.selected_filter_param_value_title); if (title != null) { title.settext(filter_value_data.tostring()); } } }
upd solution that's work me in comment below, @diljeet. put addview in runnable
public void onfilterparamvaluechanged(myclass obj) { new handler().post(new runnable(){ public void run() { addview(new myview(getcontext(), obj.gettitle())); } }); }
Comments
Post a Comment