0

チェックボックスに問題があります。チェックボックスがオンになっていない場合、一部のテキストをグレーアウトしようとしていますが、それができません。私は以前にこれを行いましたが、忘れてしまい、コードのコピーを保存していなかったので、コードがめちゃくちゃになりました。

これがジャバです。

package com.example.mobilebillforecaster;

import com.example.mbf.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

  public class Eticorporate extends Activity {
protected void onCreate(Bundle Bundle)
{
 super.onCreate(Bundle);
 setContentView(R.layout.eti_corporate);

((CheckBox)findViewById(R.id.cRoam)).setOnClickListener(new View.OnClickListener()
 {

public void onClick(View v)
  {
    if (((CheckBox)v).isChecked())
    {
      this.tbDataroam.setEnabled(true);
      this.bIntroam.setEnabled(true);
      this.dataroam.setEnabled(true);
      return;
    }
    this.tbDataroam.setEnabled(false);
    this.bIntroam.setEnabled(false);
    this.dataroam.setEnabled(false);
  }
 });

これはXMLです

  <CheckBox
    android:id="@+id/cRoam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/datalocal"
    android:layout_marginTop="5.0dip"
    android:checked="false"
    android:onClick="onCheckboxClicked"
    android:text="@string/checkroam" />

  <TextView
    android:id="@+id/dataroam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/datalocal"
    android:layout_below="@+id/bIntroam"
    android:layout_marginTop="18.0dip"
    android:enabled="false"
    android:text="@string/data_roam"
    android:textAppearance="?android:textAppearanceMedium" />

 <ToggleButton
    android:id="@+id/tbDataroam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/bIntroam"
    android:layout_marginTop="7.0dip"
    android:layout_toRightOf="@id/nationalmins"
    android:enabled="false"
    android:text="@string/data_roam" />

<Button
    android:id="@+id/bIntroam"
    android:layout_width="250.0dip"
    android:layout_height="50.0dip"
    android:layout_alignRight="@id/bundle"
    android:layout_below="@id/cRoam"
    android:enabled="false"
    android:text="@string/int_roam" />

これは簡単なことかもしれませんが、理解できません。

ありがとう、

4

1 に答える 1

0

代わりに を使用することをお勧めしますOnCheckedChangeListener

次のようになります。

((CheckBox)findViewById(R.id.cRoam)).setOnCheckedChangeListener(new OnCheckedChangeListener()
{  
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        if (isChecked)
        {
            this.tbDataroam.setEnabled(true);
            this.bIntroam.setEnabled(true);
            this.dataroam.setEnabled(true);
            return;
        }
        this.tbDataroam.setEnabled(false);
        this.bIntroam.setEnabled(false);
        this.dataroam.setEnabled(false);
    }
});

編集:

アクセスする前に、これら 3 つのウィジェットへの参照を取得する必要があります。

ToggleButton tbDataroam = (ToggleButton) findViewById(R.id.tbDataroam);

他の 2 つのウィジェットについても繰り返します...

于 2013-03-06T17:20:44.567 に答える