Android应用程序 - 乘除用户输入值的值的两种形式乘除、两种、应用程序、形式

由网友(醉長翁.)分享简介:我试图做一个Android应用程序,因为我是一个总的初学者,我想知道,如果有人可以帮助我与code。 I'm trying to make an android app, and as I am a total beginner, I am wondering if anyone could help me out...

我试图做一个Android应用程序,因为我是一个总的初学者,我想知道,如果有人可以帮助我与code。

I'm trying to make an android app, and as I am a total beginner, I am wondering if anyone could help me out with the code.

将有三个拖曳进入不同的号码,也想该应用由第一划分所述第二值,然后由第三相乘。然后在屏幕上显示的答案。

There will be three boxes to enter different numbers, and I want the app to divide the second value by the first, and then multiply it by the third. And then display the answer on screen.

和应用程序确实有一个目的AHA。

And the app does have a purpose aha.

所以像(B / A)* C

So like (b/a)*c

推荐答案

有关服用投入需要3 EditText上并点击它采取一键获取结果。

For taking inputs take 3 EditText and take one Button for get Result by Clicking on it.

按照此

public class result extends Activity
{
 private EditText edit1;
private EditText edit2;
private EditText edit3;

public void onCreate(Bundle savedInstanceState) 
{
    try
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        edit1 = (EditText)findViewById(R.id.edit1);
        edit2 = (EditText)findViewById(R.id.edit2);
        edit3 = (EditText)findViewById(R.id.edit3);

        Button click = (Button)findViewById(R.id.btn);

        click.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                int a = Integer.parseInt(edit1.getText().toString());
                int b = Integer.parseInt(edit2.getText().toString());
                int c = Integer.parseInt(edit3.getText().toString());
                double result = ((double) a/b)*c;
                Toast.makeText(result.this, Double.toString(result),Toast.LENGTH_LONG).show();
            }
        });


    }catch (Exception e) {
        e.printStackTrace();
    }
}
}

Result.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="#fff"
 >

<EditText 
   android:id="@+id/edit1"
   android:layout_width="fill_parent"
   android:layout_height="40dp"
   android:inputType="text"/>

<EditText 
   android:id="@+id/edit2"
   android:layout_width="fill_parent"
   android:layout_height="40dp"
   android:inputType="text"/>

 <EditText 
   android:id="@+id/edit3"
   android:layout_width="fill_parent"
   android:layout_height="40dp"
   android:inputType="text"/>

 <Button
   android:id="@+id/btn"
   android:layout_width="fill_parent"
   android:layout_height="40dp"
   android:text="Click"/>

</LinearLayout>
阅读全文

相关推荐

最新文章