2013-03-06 6 views
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" /> 

입니다. 내가 대신 OnCheckedChangeListener의 사용을 추천 할 것입니다

답변

0

감사합니다.

과 같을 것이다 :

((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 위젯 ...

+0

문제는 찾을 수 없다는 것입니다. this.tbdataroam. 그것을 구현하려고합니다. –

+0

글쎄, 당신이 액세스하려는 위젯에 대한 참조를 얻을 필요가 ... 내 게시물을 편집합니다. –

+0

도움을 많이 주셔서 감사합니다. –

관련 문제