Android Studio - 运行项目时计算无效

时间:2013-11-11 10:36:30

标签: java android

我之前发过一个问题,但没有得到任何回复。

只是一点背景知识,我在Android Studio中使用“带有viewpager的操作栏选项卡”作为导航创建了一个应用程序。运行应用程序时,所有页面都加载,我可以滚动并打开,没有任何问题。但由于某种原因,在运行项目时,calculate.jave(我在下面包含)不会加载/执行/工作。但是,当我只运行我的计算页面时,它可以正常运行并进行计算。

我真的希望有人可以提供帮助。 :)

请让我知道您希望我包含哪些内容,以便您进一步协助我?

calculate.java(计算值已经改变,所以请忽略数字:))

package za.co.domain.calculator;

import android.app.Activity;
import android.os.Bundle;
import java.text.DecimalFormat;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;


@SuppressWarnings("ConstantConditions")
public class calculate extends Activity {

    private Spinner selectKeyValues;

    private double i1wvalue = 0;
    private double i1lvalue = 0;
    private double i2wvalue = 0;
    private double cwvalue = 0;
    private double aw2value = 0;
    private double awvalue = 0;
    final DecimalFormat d = new DecimalFormat("##.##");


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

        selectKeyValues = (Spinner)findViewById(R.id.spinnerkeyvalues);

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

        final EditText txtenterknownvalue = (EditText) findViewById(R.id.txtenterknownvalue);
        if(txtenterknownvalue.getText().toString().length() == 0)
            txtenterknownvalue.setError("You need to enter a value!");

        final EditText calculatedi1wvalue = (EditText)findViewById(R.id.calculatedi1wvalue);
        calculatedi1wvalue.setEnabled(false);
        final EditText calculatedi2wvalue = (EditText)findViewById(R.id.calculatedi2wvalue);
        calculatedi2wvalue.setEnabled(false);
        final EditText calculatedcwvalue = (EditText)findViewById(R.id.calculatedcwvalue);
        calculatedcwvalue.setEnabled(false);
        final EditText calculatedi1lvalue = (EditText)findViewById(R.id.calculatedi1lvalue);
        calculatedi1lvalue.setEnabled(false);
        final EditText calculatedaw2value = (EditText)findViewById(R.id.calculatedaw2value);
        calculatedaw2value.setEnabled(false);
        final EditText calculatedawvalue = (EditText)findViewById(R.id.calculatedawvalue);
        calculatedawvalue.setEnabled(false);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                double userinput = Double.valueOf(txtenterknownvalue.getText().toString());
                String spinnerselection = selectKeyValues.getSelectedItem().toString();

                if(spinnerselection.equals("I1W"))
                {
                    i1wvalue = (userinput);
                    i1lvalue = (userinput / 85);
                    i2wvalue = (18 * userinput);
                    cwvalue = (32 * userinput);
                    aw2value = (2 * userinput);
                    awvalue = (4 * userinput);
                }
                else if(spinnerselection.equals("I2W"))
                {
                    i1wvalue = (userinput / 8);
                    i1lvalue = (userinput / 18);
                    i2wvalue = (userinput);
                    cwvalue = (userinput * 0.1);
                    aw2value = (userinput * 5.6);
                    awvalue = (9 * userinput * 9.1);
                }
                else if(spinnerselection.equals("CW"))
                {
                    i1wvalue = (userinput / 5.02);
                    i1lvalue = (userinput / 0.520);
                    i2wvalue = (userinput / 0.681);
                    cwvalue = (userinput);
                    aw2value = (userinput * 1.12);
                    awvalue = (9 * userinput / 2235.0);
                }
                else if(spinnerselection.equals("I1L"))
                {
                    i1wvalue = (userinput * 0.2356);
                    i1lvalue = (userinput);
                    i2wvalue = (0.236 * userinput * 1.5);
                    cwvalue = (0.382 * userinput * 21.05);
                    aw2value = (1.5 * userinput * 60.23);
                    awvalue = (6 * userinput * 2);
                }
                else if(spinnerselection.equals("AW2"))
                {
                    i1wvalue = (userinput * 8.2);
                    i1lvalue = (userinput * 6);
                    i2wvalue = (userinput * 1);
                    cwvalue = (userinput * 2);
                    aw2value = (userinput);
                    awvalue = (4.2 * userinput);
                }
                else if(spinnerselection.equals("AW"))
                {
                    i1wvalue = (userinput / 2);
                    i1lvalue = (userinput / 2);
                    i2wvalue = (userinput / 2);
                    cwvalue = (userinput / 2);
                    aw2value = (userinput / 2);
                    awvalue = (userinput);
                }

                calculatedi1wvalue.setText("I1W - Central Incisor Width: " + d.format(i1wvalue));
                calculatedi2wvalue.setText("I2W - Lateral Incisor Width: " + d.format(i2wvalue));
                calculatedcwvalue.setText("CW - Cuspid/ canine Width: " + d.format(cwvalue));
                calculatedi1lvalue.setText("I1L - Central Incisor Length: " + d.format(i1lvalue));
                calculatedaw2value.setText("AW2 - Half Arch Width: " + d.format(aw2value));
                calculatedawvalue.setText("AW - Full Arch Width: " + d.format(awvalue));
            }


        });

    }}

calculate_values.xml

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity$PlaceholderFragment"
        >
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lblcontentcalculatepage"
        android:id="@+id/calculateheading"
        android:gravity="center_horizontal"
        android:layout_marginBottom="@dimen/abc_dropdownitem_text_padding_left"
        android:layout_marginTop="@dimen/abc_dropdownitem_text_padding_left" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lblcontentcalcpageselect"
        android:id="@+id/labelenterknownvalue"
        android:textStyle="bold" />


    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/spinnerkeyvalues"
        android:layout_gravity="left"
        android:entries="@array/keyvalues_array"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lblentervaluecalcpage"
        android:id="@+id/labelentervalue"
        android:textStyle="bold" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:id="@+id/txtenterknownvalue"
        android:inputType="numberDecimal"
        android:numeric="integer|decimal" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/calculate"
        android:id="@+id/but_calculate"
        android:layout_gravity="center_horizontal" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedi1wvalue"
        android:text="@string/lbliw1calcpage"
        android:inputType="text"
        android:textIsSelectable="false"
        android:enabled="false" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedi2wvalue"
        android:text="@string/lbli2wcalcpage"
        android:inputType="text"
        android:enabled="false" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedcwvalue"
        android:text="@string/lblcwcalcpage"
        android:inputType="text"
        android:enabled="false" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedi1lvalue"
        android:text="@string/lbli1lcalcpage"
        android:inputType="text"
        android:enabled="false" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedaw2value"
        android:text="@string/lblaw2calcpage"
        android:inputType="text"
        android:enabled="false" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calculatedawvalue"
        android:text="@string/lblawcalcpage"
        android:inputType="text"
        android:enabled="false" />

</LinearLayout>

AndroidManifest.xml - 这就是我将活动添加到我的Manifest文件的方式,我想我会确认它也是正确的:)

<activity android:name=".calculate" android:label="@string/but_calculate">
        <intent-filter>
            <action android:name="za.co.gumguru.aesthetictoothproportionscalculator.CALC" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

Logcat:您可以按clicking here

查看日志

0 个答案:

没有答案