Math Android应用程序中的简单数学公式

Math Android应用程序中的简单数学公式,math,Math,这是我第一次发帖,在尝试了几种不同版本的解决方案后,我觉得我所要求的有点超出了我目前的能力 我目前正在为我的公司创建一个简单的应用程序,该应用程序将用作销售工具。在我的行业中,能够输入维度为客户获取快速报价对该领域的销售人员非常有帮助 我想尝试做的是创建一个文本字段,允许销售人员输入L(长度)、W(宽度)和D(深度) 幕后(java)L将通过一个简单的数学方程,考虑到预先确定的余量。然后将答案放入一个结果区域,让他们知道项目的空白大小。 例L=8.0625-->(D*2+0.125)*2+L--

这是我第一次发帖,在尝试了几种不同版本的解决方案后,我觉得我所要求的有点超出了我目前的能力

我目前正在为我的公司创建一个简单的应用程序,该应用程序将用作销售工具。在我的行业中,能够输入维度为客户获取快速报价对该领域的销售人员非常有帮助

我想尝试做的是创建一个文本字段,允许销售人员输入L(长度)、W(宽度)和D(深度)

幕后(java)L将通过一个简单的数学方程,考虑到预先确定的余量。然后将答案放入一个结果区域,让他们知道项目的空白大小。 例L=8.0625-->(D*2+0.125)*2+L-->毛坯长度=14.625

我意识到这似乎有点令人困惑,但它实际上只是一个简单的等式,使用用户输入的信息,添加到静态等式中,然后将结果发布在同一页面上

编辑:我解决了它的一些方面,但现在我在尝试从整数到小数时遇到了崩溃。我可以输入6,但不能输入6.25。有什么建议吗

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_test4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.design.test4">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20dp"
    android:text="Length"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:textSize="20dp"
    android:id="@+id/length1"
    android:gravity="right"
    android:hint="Enter" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:paddingRight="30dp"
        android:text="Width"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:textSize="20dp"
    android:id="@+id/width1"
    android:gravity="right"
    android:hint="Enter" />

    </LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:paddingRight="30dp"
        android:text="Depth"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:textSize="20dp"
    android:id="@+id/depth1"
    android:gravity="right"
    android:hint="Enter" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<Button
    android:text="B Flute"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/button"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="20dp"
    android:onClick="onButtonClick1" />

    <Button
        android:text="C Flute"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/button2"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        android:onClick="onButtonClick2" />

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:paddingRight="30dp"
        android:text="Blank Width"/>

<TextView
    android:text="Answer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/depth1"
    android:textSize="20dp"
    android:gravity="right"
    android:id="@+id/blank_width1" />

    </LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:paddingRight="30dp"
        android:text="Blank Length"/>

<TextView
    android:text="Answer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="right"
    android:textSize="20dp"
    android:id="@+id/blank_length1" />

    </LinearLayout>





</LinearLayout>







@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test4);
}

double ba_width = (2.625);
double ba_length = (.625);


public void onButtonClick1(View v){
    EditText e1 = (EditText)findViewById(R.id.length1);
    EditText e2 = (EditText)findViewById(R.id.width1);
    EditText e3 = (EditText)findViewById(R.id.depth1);
    TextView t1 = (TextView)findViewById(R.id.blank_width1);
    TextView t2 = (TextView)findViewById(R.id.blank_length1);
    double num1 = Integer.parseInt(e1.getText().toString());
    double num2 = Integer.parseInt(e2.getText().toString());
    double num3 = Integer.parseInt(e3.getText().toString());
    double sum1 = num1 + (num3 + num3 + ba_width);
    double sum2 = num2 + (num3 + num2 + num3 + num2 + num3 + ba_length);
    t1.setText(Double.toString(sum1));
    t2.setText(Double.toString(sum2));
}

double ca_width = (3.25);
double ca_length = (.6875);


public void onButtonClick2(View v) {
    EditText e1 = (EditText) findViewById(R.id.length1);
    EditText e2 = (EditText) findViewById(R.id.width1);
    EditText e3 = (EditText) findViewById(R.id.depth1);
    TextView t1 = (TextView) findViewById(R.id.blank_width1);
    TextView t2 = (TextView) findViewById(R.id.blank_length1);
    double num1 = Integer.parseInt(e1.getText().toString());
    double num2 = Integer.parseInt(e2.getText().toString());
    double num3 = Integer.parseInt(e3.getText().toString());
    double sum1 = num1 + (num3 + num3 + ca_width);
    double sum2 = num2 + (num3 + num2 + num3 + num2 + num3 + ca_length);
    t1.setText(Double.toString(sum1));
    t2.setText(Double.toString(sum2));
}

}

@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test4);
}
双巴乌宽度=(2.625);
双巴乌长度=(.625);
公共无效按钮CLICK1(视图五){
EditText e1=(EditText)findViewById(R.id.length1);
EditText e2=(EditText)findViewById(R.id.width1);
EditText e3=(EditText)findViewById(R.id.depth1);
TextView t1=(TextView)findViewById(R.id.blank_width1);
TextView t2=(TextView)findViewById(R.id.blank_length1);
double num1=Integer.parseInt(e1.getText().toString());
double num2=Integer.parseInt(e2.getText().toString());
double num3=Integer.parseInt(e3.getText().toString());
双sum1=num1+(num3+num3+ba_宽度);
双集水坑2=num2+(num3+num2+num3+num2+num3+ba_长度);
t1.setText(Double.toString(sum1));
t2.setText(Double.toString(sum2));
}
双ca_宽度=(3.25);
双ca_长度=(.6875);
公共无效按钮CLICK2(视图五){
EditText e1=(EditText)findViewById(R.id.length1);
EditText e2=(EditText)findViewById(R.id.width1);
EditText e3=(EditText)findViewById(R.id.depth1);
TextView t1=(TextView)findViewById(R.id.blank_width1);
TextView t2=(TextView)findViewById(R.id.blank_length1);
double num1=Integer.parseInt(e1.getText().toString());
double num2=Integer.parseInt(e2.getText().toString());
double num3=Integer.parseInt(e3.getText().toString());
双sum1=num1+(num3+num3+ca_宽度);
双集水坑2=num2+(num3+num2+num3+num2+num3+ca_长度);
t1.setText(Double.toString(sum1));
t2.setText(Double.toString(sum2));
}
}

什么部件导致您出现问题?显示文本字段?还是做数学?老实说,两者都有一点。我有关于如何将输入字段放置到位的一般要点,但在运行完公式后,我遇到了重定向输入以在页面上显示文本的问题。。。。那么你的问题不够集中,应该以“太宽泛”来结束。了解如何在您选择的Android开发框架中使用表单。如果这引起了一个具体的问题,请随意提问。同样,如果你有一个关于用Java做数学的具体问题,可以问这个问题。FWIW我无法计算出你的数学问题。为什么不设置三个文本框,每个维度一个?为什么销售人员必须知道津贴?有三个文本框,每个文本框提供不同的维度供他们输入。如果客户说他们需要L=6、W=4和D=2,那么销售人员可以在字段中输入。然后,“解决方案”将显示为该项目的空白大小,这将根据框而变化。我只是想知道如何建立“L+1.3125+(D*2)”的一般方程,并把解放到正确的位置。(1.3125为本箱的余量)