0
私は、弾丸のドロップとターゲットにする時間を計算する簡単な弾道アプリを作ろうとしています。私はそれが必要な場所にすべてを持っていますが、私はそれを試して結果を待ちますが、私がそこにある計算をしていないようです。私のための任意の提案?私の計算が私のアプリに表示されないのはなぜですか?
package com.example.koryhershock.testapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
Button btn = (Button)findViewById(R.id.button1);
final EditText et1 = (EditText)findViewById(R.id.muzzleVelocity);
final EditText et2 = (EditText)findViewById(R.id.targetRange);
final TextView time = (TextView)findViewById(R.id.textView1);
final TextView bulletdrop = (TextView)findViewById(R.id.textView2);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int x = new Integer(et1.getText().toString());
int y = new Integer(et2.getText().toString());
double timetotarget = x/y;
double grav = 4.9;
double timesquared = timetotarget * timetotarget;
double drop = grav * timesquared;
time.setText("Time to Target: " + timetotarget + " seconds");
bulletdrop.setText("Bullet Drop: " + drop + " meters");
}
});
}
}
ログステートメントをonClickメソッドに配置して、呼び出されていることを確認できますか? –
私は、時間と目標の値を設定するために別のテキストに値を設定します。すべての値に対して0を返します。 –
'int'の代わりに' x'と 'y'を' double'とします。 –