Android按钮需要多次点击

时间:2011-07-31 23:58:48

标签: android

我正在创建一个应用程序。而且我是新的相对论。如果我尝试让按钮执行其操作,则需要多次单击。例如,现在,如果我按它,我将得到一个空白文本视图。然后,如果我第二次按它,我会在文本视图上收到一条消息,表示无效。然后,当我再次按下按钮时,它最终会输出数据。(代码是将三个东西放在一起)。如果有人能提供帮助,那将非常感激。谢谢

代码继续但是这个

package com.example
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TestingActivity<textField> extends Activity {
    /** Called when the activity is first created. */
    EditText field1;
    EditText field2;
    TextView text1;
    EditText field3;
    EditText field4;
    String fnum;
    String snum;
    String tnum;
    String ftnum;
    String RAnswer;
    double num1;
    double num2;
    double num3;
    double num4;
    double num5;
    double num6;
    double num7;
        double num8;
    double num9;
    double num10;
    double num11;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button1 = (Button) findViewById(R.id.button1);
        field1 = (EditText) findViewById(R.id.tf1);
        text1 = (TextView) findViewById(R.id.text1);
        text2 = (TextView) findViewById(R.id.text2);
        text3 = (TextView) findViewById(R.id.text3);
        field2 = (EditText) findViewById(R.id.tf2);
        field3 = (EditText) findViewById(R.id.tf3);
        field4 = (EditText) findViewById(R.id.tf4);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override   
            public void onClick(View v) {       
                text1.setText(RAnswer);
                fnum = field1.getText().toString();
                snum = field2.getText().toString();
                tnum = field3.getText().toString();
                ftnum = field4.getText().toString();
                RAnswer = Double.toString(num6);
                num1 = Double.parseDouble(fnum);
                num2 = Double.parseDouble(snum);
                num3 = Double.parseDouble(tnum);
                num4 = Double.parseDouble(ftnum);
                RAnswer = Double.toString(num11);
                num9 = num2 - num1;
                num10 = num4 - num3;
                num11 = num10 / num9;`

1 个答案:

答案 0 :(得分:0)

你的onClick方法的结尾似乎缺失了,但我注意到了

text1.setText(RAnswer);

是第一行。我猜它应该在

之后
RAnswer = Double.toString(num11);