Set text if selected android checkbox

Asked

Viewed 567 times

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 is to write paper, in the bookmark windows info, only that 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);

Awaiting suggestions, thank you!

1 answer

2

Try to use the Istener: setOnCheckedChangeListener

new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){
                        Log.i("valor","papel");
                    }else{
                        Log.i("valor", ""+isChecked);
                    }
                }
            }
  • I didn’t get to test, but I got another way here declaring a variable as string, in case the paper was selected this variable would be = the paper, I know it’s not the right way, but so far it’s working

Browser other questions tagged

You are not signed in. Login or sign up in order to post.