Assigning Integer Value to String. Android/Java -


i'm new both java , android , working on program has 2 edittext's in row. first edittext want string , second integer assigned string.

to make more specific, user inputs homework , 15 , want number saved such in future when user inputs assignment homework value, value multiplies 15.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal">          <edittext              android:id="@+id/register_assign_edit"              android:layout_width="fill_parent"              android:layout_height="wrap_content"              android:gravity="center_horizontal"              android:hint="@string/example_assign"              android:singleline="true"              android:inputtype="textcapwords"              android:layout_weight="1">          </edittext>          <edittext              android:id="@+id/register_weight_edit"              android:layout_width="fill_parent"              android:layout_weight="1"              android:layout_height="wrap_content"              android:hint="@string/example_weight"              android:layout_marginleft="3dp"              android:gravity="center_horizontal"              android:inputtype="number"              android:singleline="true"              android:maxlength="2">          </edittext>          </linearlayout>  

that's xml file

this .java file

public void onaddnewclicked(view v){         inflateeditrow(null, null);         v.setvisibility(view.gone);     }      private void inflateeditrow(string name, string name1){         layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service);         final view rowview = inflater.inflate(r.layout.new_class, null);          final edittext register_assign = (edittext) rowview.findviewbyid(r.id.register_assign_edit);         final edittext register_weight = (edittext) rowview.findviewbyid(r.id.register_weight_edit);          if (name != null && !name.isempty()) {             register_assign.settext(name);             register_weight.settext(name1);         } else {             mexclusiveemptyview = rowview;         }           mcontainerview.addview(rowview, mcontainerview.getchildcount()-1);     } 

i tried change parameter of string name2 integer weight , when called in onaddnewclicked inflateeditrow(null, (integer) null), program crashing.

to convert string containing expected integer value, use:

integer.valueof(yourstring); 

bear in mind have try-catch conversion, since if original string not consist of valid integer value, numberformatexception thrown.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -