无法在导航抽屉中计算

时间:2016-05-21 07:01:50

标签: android

我一直试图在导航抽屉里制作一个计算器,但它给了我一个错误,我无法计算。

如何解决此错误?

public class SNFFragment extends Fragment {

    public SNFFragment() {
}

EditText edit1, edit2;
Button btn;
android.widget.TextView TextView;
double value1, value2;
double value3;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.snf_layout, container, false);

    edit1 = (EditText) view.findViewById(R.id.edit1);
    edit2 = (EditText) view.findViewById(R.id.edit2);
    btn = (Button) view.findViewById(R.id.btn);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (edit1.getText().toString().isEmpty()) {
                edit1.setError("Enter value1");
            } else if (edit2.getText().toString().isEmpty()) {
                edit2.setError("Enter value2");
            } else {
                calculate();
            }

        }

        private void calculate() {
            try {
                value1 = Double.valueOf(edit1.getText().toString());
                value2 = Double.valueOf(edit2.getText().toString());

                Log.d("value1", String.valueOf(value1));
                Log.d("value2", String.valueOf(value2));

                value3 = (0.25 * value1 + value2 * 0.21 + 0.36);

                //When the button is clicked, call the calculate method.

                TextView.setText(String.format("Answer: %.2f", value3));
            } catch (NumberFormatException e) {
                Log.d("value1", String.valueOf(value1));
                Log.d("value2", String.valueOf(value2));

                Log.d("Exception", String.valueOf(e));
            }
        });
         return view;
}

1 个答案:

答案 0 :(得分:0)

我建议您将if(!empty($_GET['datetime'])) { $dt = $_GET['datetime']; $dttm = strtotime($dt); echo $dttm; if($dttm < time()) { echo "<center><strong> Operation not possible !</strong></center>"; } } else if //... 函数移到calculate()回调函数之外,而是将其作为onClickListener的私有函数,以便您的代码看起来像这样::

SNFFragment

请尝试一下,如果有帮助请告诉我们。