equation - how to show fraction with denomainator, horizantal line and numerator on run time in android -
is there any why show fraction neat , clean in android denominator, horizontal line , numerator
for example
4/5+x + 3
would be
4
_____ + 3
5 + x
actually want show algebraic equation on run time.
please tell me answer working on since 4 or 5 days no success achieved.
try this:
mainactivity code:
public class mainactivity extends activity {
edittext etinput; linearlayout resultlayout; button btnresult; viewtreeobserver mvto; int widthofline; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); etinput = (edittext) findviewbyid(r.id.etinput); btnresult = (button) findviewbyid(r.id.btnshowres); btnresult.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string temp = etinput.gettext().tostring().trim(); if(temp.contains("/")){ system.out.println("inside if"); string[] numarr = temp.split("/"); log.d("dj", "num1: & num2: "+numarr[0]+" "+numarr[1]); showresults(numarr[0], numarr[1]); } else toast.maketext(getbasecontext(), "pattern invalid", toast.length_short).show(); } }); resultlayout = (linearlayout) findviewbyid(r.id.showresultlay); } protected void showresults(string numerator, string denominator) { final linearlayout linchild = new linearlayout(getbasecontext()); linearlayout.layoutparams childparams = new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); linchild.setgravity(gravity.center); linchild.setlayoutparams(childparams); linchild.setorientation(linearlayout.vertical); textview tvnumerator = new textview(getbasecontext()); linearlayout.layoutparams tvparams = new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); tvnumerator.setlayoutparams(tvparams); linchild.addview(tvnumerator); tvnumerator.settext(numerator); tvnumerator.settextcolor(color.black); tvnumerator.settextsize(25); final view dividerview = new view(getbasecontext()); dividerview.setbackgroundcolor(color.red); linchild.addview(dividerview); final textview tvdenominator = new textview(getbasecontext()); linearlayout.layoutparams tv1params = new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); tvdenominator.setlayoutparams(tv1params); linchild.addview(tvdenominator); tvdenominator.settextcolor(color.black); tvdenominator.settext(denominator); tvdenominator.settextsize(25); mvto = linchild.getviewtreeobserver(); mvto.addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { widthofline = tvdenominator.getwidth(); linearlayout.layoutparams viewparams = new linearlayout.layoutparams(layoutparams.wrap_content, 5); viewparams.width = widthofline; dividerview.setlayoutparams(viewparams); } }); resultlayout.addview(linchild); }
}
layout file:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" 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="dj.numeratordenominator.main.mainactivity" > <edittext android:id="@+id/etinput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="26dp" android:ems="10" android:inputtype="textnosuggestions" > <requestfocus /> </edittext> <linearlayout android:id="@+id/showresultlay" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/btnshowres" android:layout_centerhorizontal="true" android:layout_margintop="30dp" > </linearlayout> <button android:id="@+id/btnshowres" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/etinput" android:layout_margintop="10dp" android:layout_centerhorizontal="true" android:text="button" /> </relativelayout>
Comments
Post a Comment