android —使用输入数据(数字)进行计算(显示图表?)

android —使用输入数据(数字)进行计算(显示图表?),第1张

概述我开始学习android,我有几个问题.我的主要程序如下:publicclassRadiation_overflowActivityextendsActivityimplementsOnClickListener{EditTextinit_cores;Viewfinal_cores;/**Calledwhentheactivityisfirstcreated.*/@Override

我开始学习android,我有几个问题.
我的主要程序如下:

public class Radiation_overflowActivity  extends Activity implements OnClickListener {    EditText init_cores;        VIEw final_cores;    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);    //Set up click Listeners    init_cores=(EditText) findVIEwByID(R.ID.init_cores);    //init_cores.setonClickListener(this);    final_cores=(VIEw) findVIEwByID(R.ID.final_cores);    final_cores.setonClickListener(this);     }    //called when a button is clicked    public voID onClick(VIEw v) {        switch (v.getID()){        case R.ID.final_cores:            //int r = Integer.parseInt(init_cores.getText().toString().trim());            double initcores=Double.parseDouble(init_cores.getText().toString().trim());            double l=2,t=2;            double fcores=initcores*Math.exp(-l*t);            Intent i=new Intent(this,calcs.class);            i.putExtra("value",fcores);            startActivity(i);            break;         }       }      }

另外,我的main.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:orIEntation="vertical" ><TextVIEw    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:text="@string/initial_cores" /><EditText    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:ID="@+ID/init_cores"    androID:inputType="numberDecimal" /><button    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:ID="@+ID/final_cores"    androID:text="@string/calculate" /></linearLayout>

我的calcs.java:

public class calcs extends Activity{    TextVIEw calcs_final;    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.calcs);        calcs_final=(TextVIEw) findVIEwByID(R.ID.calcs_final);        double f=getIntent().getExtras().getDouble("value");        calcs_final.setText(Double.toString(f));}}

我的calcs.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" >    <TextVIEw        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:ID="@+ID/calcs_final"         androID:text="@string/result" /></linearLayout>

我想做这个:

用户将数据输入到edittext(init_cores)中,然后我要进行一些计算以计算final_cores并将其显示给用户.

我无法显示结果.我正在启动另一个活动(calcs.class和calcs.xml).
我必须在哪里进行计算?到calcs.class?
现在,用户输入一个数字,按下“计算”按钮,然后显示文本(来自strings.xml)“核心数””,但不显示结果.

另外,如果可以给我一些指导,我可以使用数据和计算中的输入来作图吗?

最后,我的方法正确吗?

谢谢!

解决方法:

据我认为您的final_cores是一个视图,您希望获得您的edittext的值进行计算(希望我没有错)

所以,做些类似的事情,

public voID OnClick(VIEw v) {    switch (v.getID()){    case R.ID.final_cores:        int r = Integer.parseInt(init_cores.getText().toString().trim());        Intent i=new Intent(this,calcs.class);        i.putExtra("value",r);        startActivity(i);        break;    }}

从init_cores编辑文本中删除onClickListener.并使用Calcs.class获取r的值

int r = getIntent().getExtras().getInt("value");

另外,请确保在编辑文本中始终输入数值,以便可以将其解析为Integer.

试试这个,让我知道会发生什么..

谢谢,

总结

以上是内存溢出为你收集整理的android —使用输入数据(数字)进行计算(显示图表?)全部内容,希望文章能够帮你解决android —使用输入数据(数字)进行计算(显示图表?)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1094730.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存