Android的 - 使计算的输入数据(数字) - (显示图形)图形、数字、数据、Android

由网友(逆流)分享简介:我开始学习Android和我有几个问题。我有我的主要程序为:I am starting to learn android and i have a few questions.I have my main program as:public class Radiation_overflowActivity e...

我开始学习Android和我有几个问题。 我有我的主要程序为:

I am starting to learn android and i have a few questions. I have my main program as:

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:

Also, my 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:

My 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:

My 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>

我想这样做:

I want to do this:

用户输入数据到的EditText(init_cores),然后我希望做一些计算来计算final_cores并显示给用户。

The user enters data into the edittext (init_cores) and then i want to make some calculations to compute the final_cores and show it to the user.

我有显示results.I我开始另一个活动(calcs.class和calcs.xml)的麻烦。 当我必须这样做计算?到calcs.class? 现在,用户输入一个号码,presses计算按钮,然后它显示的文本(从strings.xml中)核心数,但不是结果

I have trouble for showing the results.I am starting another activity (calcs.class and calcs.xml). Where i must do the calculations?To the calcs.class? Right now,the user enters a number ,presses the "Calculate" button and then it shows the text (from the strings.xml) "Number of cores"" ,but not the result.

另外,我可以使用输入的数据,并从我的计算,使一个阴谋吗?如果你能给我一些这方面的方向。

Also, can i use the input from the data and from my calculations and make a plot?If you could give me some directions to this.

最后,就是我的做法对吗?

Finally,is my approach right?

感谢您!

推荐答案

根据我觉得你的 final_cores 是,你想要得到你的EditText的价值观点计算(希望我没看错)

As per I think your final_cores is a view on which, you want to get your edittext's value for calculation(Hope I am not wrong)

于是,在做这样的事情,

So, just do Something like,

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 的EditText删除 onClickListener 。并获得研究值的 Calcs.class

Remove onClickListener from your init_cores edittext. And get values of r in your Calcs.class using

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

另外,请务必在总您输入数值的编辑文本,以便它可以是可解析为整数。

Also be sure in your edit text always you are entering numeric values so it can be parsable into Integer..

试试这个,让我知道发生什么事。

Try this and let me know what happen..

谢谢

阅读全文

相关推荐

最新文章