I just want to make a simple app that multiply two different user inputs, and shows the result in resultview method on onClick listener which is the "Calculate" button. Could you guys show me the block of code could do that, i've already declared the widgets and stuff, all i need is the multiply method.. please help I am now Programmer, and trying to learn. Thanks, your help will be greatly appreciated.
package com.example.alexm.percentcal;
import android.app.ActionBar;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button cal_button = (Button) findViewById(R.id.cal_button);
final EditText percentBox = (EditText) findViewById(R.id.percentBox);
final EditText valuebox = (EditText) findViewById(R.id.valueBox);
final TextView resultview = (TextView) findViewById(R.id.result);
cal_button.setOnClickListener(new View.OnClickListener());
@Override
public void onClick(View v){
}
}
}
Write below code inside of onClick of cal_button
int val1 = Integer.parseInt(percentBox.getText());
int val2 = Integer.parseInt(valueBox.getText());
//as you can not set int value to TextView, so convert it to string.
resultView.setText(String.valueOf(val1*val2));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.