java - How to Display the computed perimeter using Toast -
my java
import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.edittext; import android.widget.radiogroup; import android.widget.toast; import android.widget.radiogroup.oncheckedchangelistener; import android.widget.textview; public class mainactivity extends activity{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_main); radiogroup groupradio=(radiogroup)findviewbyid(r.id.radiogroup1); final edittext squareedt=(edittext)findviewbyid(r.id.squareedittext); final edittext reclengthedt=(edittext)findviewbyid(r.id.reclengthedittext); final edittext recwidthedt=(edittext)findviewbyid(r.id.recwidthedittext); final edittext circleedt=(edittext)findviewbyid(r.id.circleedittext); final textview side=(textview) findviewbyid(r.id.labelside); final textview length=(textview) findviewbyid(r.id.labellength); final textview width=(textview) findviewbyid(r.id.labelwidth); final textview radius=(textview) findviewbyid(r.id.labelradius); squareedt.setvisibility(view.invisible); reclengthedt.setvisibility(view.invisible); recwidthedt.setvisibility(view.invisible); circleedt.setvisibility(view.invisible); side.setvisibility(view.invisible); length.setvisibility(view.invisible); width.setvisibility(view.invisible); radius.setvisibility(view.invisible); groupradio.setoncheckedchangelistener(new oncheckedchangelistener() { public void oncheckedchanged(radiogroup group, int checkedid) { if(checkedid==r.id.rbt1) { side.setvisibility(view.visible); squareedt.setvisibility(view.visible); float una = float.parsefloat(squareedt.gettext().tostring()); float perimeter = una * una; toast.maketext(this, string.valueof("the perimeter of square " + perimeter),toast.length_long).show(); length.setvisibility(view.invisible); width.setvisibility(view.invisible); reclengthedt.setvisibility(view.invisible); recwidthedt.setvisibility(view.invisible); radius.setvisibility(view.invisible); circleedt.setvisibility(view.invisible); } else if(checkedid==r.id.rbt2) { length.setvisibility(view.visible); width.setvisibility(view.visible); reclengthedt.setvisibility(view.visible); recwidthedt.setvisibility(view.visible); side.setvisibility(view.invisible); squareedt.setvisibility(view.invisible); radius.setvisibility(view.invisible); circleedt.setvisibility(view.invisible); } else if(checkedid==r.id.rbt3) { radius.setvisibility(view.visible); circleedt.setvisibility(view.visible); length.setvisibility(view.invisible); width.setvisibility(view.invisible); reclengthedt.setvisibility(view.invisible); recwidthedt.setvisibility(view.invisible); side.setvisibility(view.invisible); squareedt.setvisibility(view.invisible); } } }); } }
i problem code
toast.maketext(this, string.valueof("the perimeter of square " + perimeter),toast.length_long).show();
and error this;the method maketext(context, charsequence, int) in type toast not applicable arguments (new radiogroup.oncheckedchangelistener(){}, string, int)
my xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/relativelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.cell.phone.mainactivity$placeholderfragment" > <radiogroup android:id="@+id/radiogroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" > <radiobutton android:id="@+id/rbt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/square" /> <radiobutton android:id="@+id/rbt2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rectangle" /> <radiobutton android:id="@+id/rbt3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/circle" /> </radiogroup> <textview android:id="@+id/labelside" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/radiogroup1" android:layout_below="@+id/radiogroup1" android:layout_marginleft="15dp" android:layout_margintop="22dp" android:text="@string/side" android:textappearance="?android:attr/textappearancelarge" /> <edittext android:id="@+id/squareedittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/labelside" android:layout_alignbottom="@+id/labelside" android:layout_marginleft="16dp" android:layout_torightof="@+id/labelside" android:ems="10" android:inputtype="number" > <requestfocus /> </edittext> <edittext android:id="@+id/reclengthedittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/labelside" android:layout_alignbottom="@+id/labelside" android:layout_marginleft="16dp" android:layout_torightof="@+id/labelside" android:ems="10" android:inputtype="number" /> <textview android:id="@+id/labellength" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/labelside" android:layout_alignbottom="@+id/labelside" android:layout_alignleft="@+id/radiogroup1" android:text="@string/length" android:textappearance="?android:attr/textappearancelarge" /> <edittext android:id="@+id/recwidthedittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/squareedittext" android:layout_below="@+id/squareedittext" android:ems="10" android:inputtype="number" /> <textview android:id="@+id/labelwidth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/recwidthedittext" android:layout_alignbottom="@+id/recwidthedittext" android:layout_alignleft="@+id/radiogroup1" android:text="@string/width" android:textappearance="?android:attr/textappearancelarge" /> <edittext android:id="@+id/circleedittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/labelside" android:layout_alignbottom="@+id/labelside" android:layout_marginleft="16dp" android:layout_torightof="@+id/labelside" android:ems="10" android:inputtype="number" /> <textview android:id="@+id/labelradius" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/labelside" android:layout_alignbottom="@+id/labelside" android:layout_alignleft="@+id/radiogroup1" android:text="@string/radius" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/recwidthedittext" android:layout_centerhorizontal="true" android:layout_margintop="46dp" android:gravity="center_vertical|center_horizontal|center" android:text="" />
change:
toast.maketext(this, string.valueof("the perimeter of square " + perimeter),toast.length_long).show();
to:
toast.maketext(mainactivity.this, string.valueof("the perimeter of square " + perimeter),toast.length_long).show();
this
here refers oncheckedchangelistener not applicable maketext(context, charsequence, int)
. mainactivty.this
context.
Comments
Post a Comment