我对应用程序制作完全陌生,我想做一些有两个 EditTexts(仅限数字)的东西,然后将它们划分并变成百分比并显示在 TextView 中。不幸的是,我不知道我所做的是否正确。这是我的代码
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;
public class FirstInformation extends Activity {
EditText eT4 = (EditText)findViewById(R.id.editText4);
EditText eT5 = (EditText)findViewById(R.id.editText5);
TextView tV6 = (TextView)findViewById(R.id.textView6);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_information);
if (eT4 != null && eT5 != null){
double numerator = (double) Integer.parseInt(eT4.getText().toString());
double denominator = (double) Integer.parseInt(eT5.getText().toString());
double textView = Math.round(numerator/denominator)*100;
tV6.setText(textView+"");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.first_information, menu);
return true;
}
public void updateTextView() {
if (eT4 != null && eT5 != null){
double numerator = (double) Integer.parseInt(eT4.getText().toString());
double denominator = (double) Integer.parseInt(eT5.getText().toString());
double textView = Math.round(numerator/denominator)*100;
tV6.setText(textView+"");
}
return;
}
}
任何反馈都会很棒。太感谢了!