Android Programming Lecture 3
To add two numbers Place Textfield – Number field Select EditText , set the property hint PlainTextView from Widget : To display message. Place the button from the widget
Button Click function Take MainActivity.java from Java folder. Write down a public function for button click . Public onButtonClick(View v) //Alt + Enter to import the class. { EditText e1=(EditText)findViewById(R.id.editText);
EditText e2=(EditText)findViewById(R. id EditText e2=(EditText)findViewById(R.id.editText);//Instance TextView t1=(TextView)findViewById(R.id.textView); int n1=Integer.parseInt(e1.getText.toString());
int n2=Integer.parseInt(e2.getText.toString()); int sum=n1+n2; T1.setText(Integer.toString(sum)); }
To invoke the function in the button click. Take the Button Property ,onClick(), Select the method from the combobox.
To invoke the function in the button click. Take the Button Property ,onClick(), Select the method from the combobox.
Home Work Perform Subtraction,multiplication and division operation.