android - Custom widget cannot be cast to custom widget -
i created custom widget extending edittext
looks edittext
acts little different, code, although don't think content of class problem:
public class salutationedittextlikebutton extends edittext { charsequence[] options; string selection; context context; long performclickcatch = 0; public void dontperformclickformilliseconds(long milliseconds) { performclickcatch = system.currenttimemillis() + milliseconds; } public salutationedittextlikebutton(context context) { super(context); this.context = context; disableinput(); } public salutationedittextlikebutton(context context, attributeset attributeset) { super(context, attributeset); this.context = context; disableinput(); } public salutationedittextlikebutton(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); this.context = context; disableinput(); } private void disableinput() { this.setcursorvisible(false); setkeylistener(null); } public string getselection() { return selection; } public void setselection(string selection) { this.selection = selection; this.sethint(""); this.settext(selection); this.clearcomposingtext(); } public void setoptions(charsequence[] options) { this.options = options; } @override public parcelable onsaveinstancestate() { log.d("butx", "save"); return super.onsaveinstancestate(); } @override public boolean performclick() { if (system.currenttimemillis() < performclickcatch) { return true; } alertdialog.builder builder = new alertdialog.builder(context); builder.settitle(getresources().getstring(r.string.anrede)); builder.setitems(options, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { setselection(options[which].tostring()); seterror(null); dialog.dismiss(); } }); alertdialog alertdialog = builder.create(); alertdialog.show(); this.clearcomposingtext(); return true; } }
i use class this:
final salutationedittextlikebutton salutationedittextlikebutton = (salutationedittextlikebutton) layoutinflater.from(context).inflate(r.layout.single_salutationbutton_w_style, null);
with xml layout being:
<xy.salutationedittextlikebutton xmlns:android="http://schemas.android.com/apk/res/android" style="@style/edittextstyle" android:layout_width="match_parent" android:layout_height="wrap_content"/>
at line
final salutationedittextlikebutton salutationedittextlikebutton = (salutationedittextlikebutton) layoutinflater.from(context).inflate(r.layout.single_salutationbutton_w_style, null);
i rare exception report on crittercism following exception:
caused by: java.lang.classcastexception: xy.salutationedittextlikebutton cannot cast xy.salutationedittextlikebutton
which seems odd me. had same exception other custom widgets.
this 1 occurs on samsung's galaxy s5 (sm-g900f).
any ideas on means , how fix it?
first try give id ur custom view :
<xy.salutationedittextlikebutton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/salutationedittextlikebutton" style="@style/edittextstyle" android:layout_width="match_parent" android:layout_height="wrap_content"/>
now inflate xml :
final view view = layoutinflater.from(context).inflate(r.layout.single_salutationbutton_w_style, null);
cast ur custom view layout inflator reference using custom view xml id :
final salutationedittextlikebutton salutationedittextlikebutton = (salutationedittextlikebutton) view.findviewbyid(r.id.salutationedittextlikebutton);
Comments
Post a Comment