Android应用程序 - 乘除用户输入值的值的两种形式 [英] Android app - Multiply and divide the user entered values values in the two forms

查看:243
本文介绍了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 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>

这篇关于Android应用程序 - 乘除用户输入值的值的两种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆