Set text if checked checkbox android

2

I have the following checkbox:

<CheckBox
android:id="@+id/papel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Papel" />

If it is selected it is to write paper, in the bookmark windows info, only it is writing "null"

    checkBoxListener = new View.OnClickListener() {

      @Override
      public void onClick(View v) {

        if (cbpapel.isChecked())
          tv.setText("Papel");

        if(!cbpapel.isChecked())
          tv.setText("");
      }
    };
LatLng posicao = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
customAddMarker(posicao, "TESTE", tv);

Waiting for suggestions, thanks!

    
asked by anonymous 24.03.2016 / 03:36

1 answer

2

Try using the listener: setOnCheckedChangeListener

new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){
                        Log.i("valor","papel");
                    }else{
                        Log.i("valor", ""+isChecked);
                    }
                }
            }
    
24.03.2016 / 07:15