私はアンドロイドを学び始めています。私はいくつかの質問があります。 私は私のメインプログラムを持っています、またアンドロイド - 入力データ(数値)で計算する - (グラフを表示する)
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に? 今すぐユーザーが数字を入力し、「計算」ボタンを押してから文字列(「string number」の文字列)を表示します。「結果数ではありません」
また、データから、私の計算から入力し、あなたが私にこれにいくつかの指示を与えることができれば?プロットを作る。
最後に、右?
ありがとう私のアプローチである!
:助けてくれてありがとうございます。私は自分のコードを更新しました(私は二重の値を使用しました)。それをチェックしてください。今は、(正しい場所に計算していれば)結果が表示されます。 – George
:二重値の場合は、 "double fcores = getIntent()。getExtras()。getDouble(" value ");" calcs.javaに?と私はcalcs.javaにこれを置く必要がありますか? – George
はい、必要に応じてdouble値を使用します。double fcores = getIntent()。getExtras()。getDouble( "value"); calcs.javaにも同じアクティビティでも表示されます。 – user370305