• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps EditText widget

DevHenrik

Lurker
Dec 20, 2014
9
0
54
Im quiet new to program for android.

I have got stuck with a, probably, very simple issue.

In my code I have two "EditText" to get numbers from the user and to be calculated together. But I dont get how to convert the input from text to calculateable numbers.

How do I solve this? :)

Thanks for help!
 
I got this thing working... here is the code! :) public class MainActivity extends Activity


{
private TextView showNo;
private EditText firstNo, secondNo;


@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


showNo = (TextView)findViewById(R.id.printout);
firstNo = (EditText)findViewById(R.id.firstInput);
secondNo = (EditText)findViewById(R.id.secondInput);

}


public void calculateBtn(View button) {
int no1 = Integer.parseInt(firstNo.getText().toString());
int no2 = Integer.parseInt(secondNo.getText().toString());
int calc = no1+no2;
showNo.setText( String.valueOf(calc));


}



}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones