0

Android Studio を使用。押すと振動と音が出るボタンが2つあります。2つのボタンの振動と音を有効/無効にするために、2つのスイッチをオン/オフするレイアウトにしました。コードを設定しようとしましたが、アプリを起動するとクラッシュしてエラーになります。誰かが私を助けることができますか?

これはコードJavaです:

public class SettingsActivity extends Activity {



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

    final Switch onOffSwitchvibr = (Switch)  findViewById(R.id.switch2);
    onOffSwitchvibr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton View, boolean isChecked) {
            if (isChecked) {
                onOffSwitchvibr.isEnabled();

                // The toggle is enabled
            } else {
                onOffSwitchvibr.getTextOff();
                return;
                // The toggle is disabled
            }
        }


    });

}





}

これはコード xml です。

<RelativeLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:layout_marginLeft="40dp"
    android:text="SETTINGS"
    android:textStyle="bold"
    android:textColor="#999999"
    android:textSize="15sp"/>
<View
    android:layout_width="fill_parent"
    android:layout_height="3dp"
    android:background="#B2B2B2"
    android:layout_marginTop="65dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"/>
<Switch
    android:id="@+id/switch1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/switch1"
    android:layout_marginTop="80dp"
    android:layout_marginRight="32dp"
    android:layout_marginLeft="32dp"

    android:onClick="onSwitchClicked"
    android:fontFamily="sans-serif"
    android:switchTextAppearance="@android:style/TextAppearance"/>
<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginTop="115dp"
    android:background="#999999"/>
<Switch
    android:id="@+id/switch2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/switch2"
    android:layout_marginTop="130dp"
    android:layout_marginRight="32dp"
    android:layout_marginLeft="32dp"
    android:fontFamily="sans-serif"
    android:textOn="ON"
    android:textOff="OFF"

    android:onClick="onSwitchClicked"
    android:switchTextAppearance="@android:style/TextAppearance"/>
4

1 に答える 1