android - Cast exception in eclipse designer -
how solve exception in eclipse designer when placing custom view in another.
java.lang.classcastexception: com.fitness.app.stopper cannot cast android.widget.button @ com.fitness.app.stopper.<init>(stopper.java:25).
com.fitness.app.stopper xml:
<merge xmlns:android="http://schemas.android.com/apk/res/android" > <button android:id="@+id/btnstartstopper" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_margintop="25dp" android:text="start" /> <chronometer android:id="@+id/chronometer1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/btnstartstopper" android:layout_marginleft="18dp" android:layout_torightof="@+id/btnstartstopper" android:text="chronometer" android:textsize="45sp" /> </merge>
and com.fitness.app.stopper line 25 error: button btnstart = (button) findviewbyid(r.id.btnstartstopper);
public class stopper extends linearlayout { private chronometer stopper; private boolean stopper_started = false; public stopper(context context) { super(context); } public stopper(context context, attributeset attrs) { super(context, attrs); initializelayoutbasics(context); this.stopper = (chronometer) findviewbyid(r.id.chronometer1); button btnstart = (button) findviewbyid(r.id.btnstartstopper); btnstart.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { startorstopstopper(arg0); } }); } private void initializelayoutbasics(context context) { setorientation(horizontal); final layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); inflater.inflate(r.layout.fragment_stopper, this, true);//todo change name fragment different } public void startorstopstopper(view v) { if(!stopper_started) stopper.start(); else stopper.stop(); stopper_started = !stopper_started; }
}
Comments
Post a Comment