小编Sea*_*ean的帖子

基本的帝国转换问题

为我的android编码计算工具.在输入上是英尺和英寸的距离.

我有两个分别为英尺和英寸的输入(input3和input4).在我的计算中,我试图将这两个输入转换为十进制数,以便在等式的其余部分中使用.这是我的代码中执行此操作的部分:

private void doCalculation() { 
    // Get entered input value 
    String strValue3 = input3.getText().toString(); 
    String strValue4 = input4.getText().toString();

    // Perform a hard-coded calculation 
    double imperial1 = (Integer.parseInt(strValue3) + (Integer.parseInt(strValue4) / 12));

    // Update the UI with the result to test if calc worked 
    output2.setText("Test: "+ imperial1); 
}
Run Code Online (Sandbox Code Playgroud)

我的测试值是4英尺6英寸.这个4很好,但是当它除以12时,6英寸默认为0.所以我的结果是4.0我尝试将计算减少到JUST分割操作,结果是0.0

我究竟做错了什么?(fyi:这是我第一次使用Java)

java math android

4
推荐指数
1
解决办法
209
查看次数

调用微调器的值?此外,根据微调器的值使用其他值

我有一个带有数字列表的微调器“光圈”和一个带有两个选项的微调器“模式”。当按下按钮时,我需要使用各种输入来运行计算,包括来自“光圈”的当前选择和来自“模式”的值。我如何调用微调器的值以便我可以在计算中使用它?

另外,在计算中如何使用微调器模式的选择来设置其他值?更具体地说,如果微调器设置为小,那么我在计算中使用的值是 0.015,而如果选择大我需要使用 0.028

我的其他输入是 EditText 视图,所以现在我是这样设置的:

    input = (EditText) findViewById(R.id.input1); 
    input2 = (EditText) findViewById(R.id.input2);
    input3 = (EditText) findViewById(R.id.input3); 
    input4 = (EditText) findViewById(R.id.input4);
    output = (TextView) findViewById(R.id.result); 
    output2 = (TextView) findViewById(R.id.result2);

    //aperture dropdown
    Spinner s = (Spinner) findViewById(R.id.apt);
    ArrayAdapter adapter2 = ArrayAdapter.createFromResource(        this, R.array.apertures,       
    android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(adapter2);

    //button
    final Button button = (Button) findViewById(R.id.calculate);
    button.setOnClickListener(new View.OnClickListener() {             
     public void onClick(View v) {                 
      // Perform action on click
      doCalculation();
       }         
      });
     }

private void doCalculation() { 
    // Get entered input value …
Run Code Online (Sandbox Code Playgroud)

java android spinner

4
推荐指数
1
解决办法
9377
查看次数

将十进制英尺转换为英尺和英寸?

如何将测量值从12.5英尺转换为12英尺6英尺?如何在乘以12时创建仅读取小数位的第二个数字?

现在我有两个Measurement01使用其他变量和一些数学来得到我的小数位.我用farf.setText(Measurement01 +""+"ft")将它发送到textview;

任何帮助,将不胜感激!

android decimal

1
推荐指数
1
解决办法
4138
查看次数

保留下次启动时输入的信息?

如何编写我的Android应用程序以记住用户在使用之间输入的值?

举个例子,假设我有一个EditText" input1"和spinner" input2",它会给出一个textview名为" output1"的结果.

目前,当我关闭并重新打开应用程序时,所有输入的值和计算都将丢失并重置.

我怎样才能解决这个问题?

java android retain

0
推荐指数
1
解决办法
103
查看次数

标签 统计

android ×4

java ×3

decimal ×1

math ×1

retain ×1

spinner ×1