在eclipse上也没有说有错误,就是不能在虚拟机上运行。
下面是主代码:
public class SimpleTextActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findView();
setListener();
}
double sum = 0;
private EditText ed1;
private EditText ed2;
private TextView tv1;
private Button b1;
public void findView() {
ed1 = (EditText) findViewById(R.id.edit1);
ed2 = (EditText) findViewById(R.id.edit2);
tv1 = (TextView) findViewById(R.id.text3);
b1 = (Button) findViewById(R.id.button);
}
public void setListener() {
b1.setOnClickListener((android.view.View.OnClickListener) calcB);
}
OnClickListener calcB = new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
double e1 = Double.parseDouble(ed1.getText().toString());
double e2 = Double.parseDouble(ed2.getText().toString());
sum = e1 * e2;
if (sum > 26) {
tv1.setText("@string/jianyi1");
} else if (sum < 20) {
tv1.setText("@string/jianyi3");
} else {
tv1.setText("@string/jianyi2");
}
}
};
}