我想获取用户输入的深度并对其进行数学运算以获得成本,然后将其显示给用户。我该如何去做呢?(如果我还没有注意到,我不懂Java)。谢谢。
private void estimateCost(View view){
EditText depth = findViewById(R.id.depth);
TextView cost = findViewById(R.id.cost);
String x = depth.getText().toString().trim();
cost.setText(x);
}
最佳答案
您需要解析从EditText获取的String,然后执行一些操作。
private void estimateCost(View view){
EditText depth = findViewById(R.id.depth);
TextView cost = findViewById(R.id.cost);
String x = depth.getText().toString().trim();
// parse to a number, i.e. int
int depthValue = Integer.parseInt(x);
// calculate total cost
int totalCost = ...
cost.setText(String.valueOf(totalCost));
}
关于java - 如何对编辑文本记录的数据进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47183791/