java - Calculate currency exchange using checkboxes -


i've started learning java in android studio , i'm doing simple currency exchange app. has checkboxes indicating different countries different currency values. have problem saying crashed when run emulator. (it crashes when implemented calculation inside case us). works fine displaying strings though.

java file:

public class mainactivity extends appcompatactivity { arraylist<string> selection = new arraylist<string>(); textview final_result; edittext medit;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     final_result = (textview)findviewbyid(r.id.result_text);     final_result.setenabled(false); }  public void selectcountry (view view) {     boolean checked = ((checkbox) view).ischecked();      switch (view.getid())     {         case r.id.us:             if(checked) {                 medit = (edittext)findviewbyid(r.id.edit_myr);                 double output = double.valueof(medit.gettext().tostring());                 double s;                 s=output*4.25;                 string output2=string.valueof(s);                 selection.add(output2);             }             else             {                 selection.remove("united states");             }             break;         case r.id.au:             if(checked) {                 selection.add("australia");             }             else             {                 selection.remove("australia");             }             break;         case r.id.uk:             if(checked) {                 selection.add("united kingdom");             }             else             {                 selection.remove("united kingdom");             }             break;         case r.id.jap:             if(checked) {                 selection.add("japan");             }             else             {                 selection.remove("japan");             }             break;         case r.id.ch:             if(checked) {                 selection.add("china");             }             else             {                 selection.remove("china");             }             break;         case r.id.sg:             if(checked) {                 selection.add("singapore");             }             else             {                 selection.remove("singapore");             }             break;         case r.id.in:             if(checked) {                 selection.add("india");             }             else             {                 selection.remove("india");             }             break;         case r.id.th:             if(checked) {                 selection.add("thailand");             }             else             {                 selection.remove("thailand");             }             break;     } } public void finalselection (view view) {     string final_selection = "";      for(string selections : selection)     {         final_selection = final_selection + selections + "\n";     }     final_result.settext(final_selection);     final_result.setenabled(true); } 

xml:

    <edittext     android:id="@+id/edit_myr"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_torightof="@+id/myr"     android:layout_marginright="40dp"     android:backgroundtint="@android:color/holo_red_light"/> </relativelayout>      <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/third"     android:textsize="20sp"     android:layout_margintop="15dp"     android:layout_marginbottom="8dp"     android:layout_marginleft="20dp"     android:textcolor="#000000"/> <button     android:id="@+id/button1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="convert"     android:layout_gravity="center_horizontal"     android:onclick="finalselection"/>  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/result_text"     android:layout_gravity="center_horizontal"/> 

my checkbox in xml is:

        <checkbox         android:id="@+id/us"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_weight="20"         android:onclick="selectcountry"           android:drawableleft="@drawable/united_states"/> 


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -