我在这里是菜鸟。需要一些帮助才能在EditText

时间:2017-08-13 03:13:59

标签: android add addition

我在布局中添加了微调器。我只想添加EditText值(abasic,ahra& aca)并在TextView agross 上显示结果,并使用计算按钮点击怎么样我为此放了java代码?我知道如何创建简单的计算器但是使用这些微调器代码我很困惑,如果我在主类中键入 onButtonClick 方法的代码它不起作用。我想因为微调器代码

需要做些什么
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText abasic, ahra, aca, lopfd, lophd, la;
    TextView ebasic, ehra, eca, agross, egross, loprs, hdrs, lars, td, spd, eepf, erpf, tpf, eeesi, eresi, tesi, pfesi;
    Button calculate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] months = {"Select a month", "January", "February", "February(Leap Year)", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

        ArrayAdapter<String> monthadapter = new
                ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, months);

        Spinner dropdown = (Spinner) findViewById(R.id.month);
        dropdown.setAdapter((monthadapter));
    }
}

提前谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用setOnClickListener收听点击事件

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText abasic, ahra, aca, lopfd, lophd, la;
    TextView ebasic, ehra, eca, agross, egross, loprs, hdrs, lars, td, spd, eepf, erpf, tpf, eeesi, eresi, tesi, pfesi;
    Button calculate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] months = {"Select a month", "January", "February", "February(Leap Year)", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

        ArrayAdapter<String> monthadapter = new
                ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, months);

        Spinner dropdown = (Spinner) findViewById(R.id.month);
        dropdown.setAdapter((monthadapter));


        calculate = (Button) findViewById(R.id.button);

        calculate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Do your calculation
            }
        });
    }
}