Xamarin.forms: [Bug] RadioButton not displaying text on Android

Created on 8 Aug 2020  ·  25Comments  ·  Source: xamarin/Xamarin.Forms

Description

After updating to Xamarin.Forms 4.8, radio buttons no longer display their text under Android. Same code works under 4.7.

Steps to Reproduce

  1. Create new Xamarin.Forms blank page app
  2. Add a radio button to the main page:
    <RadioButton Margin="5" Text="Test" />
  3. Make sure the Xamarin.Forms NuGet packages are updated to 4.8.0.1269 and run the app under Android.

Expected Behavior

The radio button displays the text "Test" to the right.

Actual Behavior

Only the circle of the radio button is displayed, with no text.

Basic Information

  • Version with issue: 4.8.0.1269
  • Last known good version: 4.7.0.1260
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:

    • Android: 9.0

Screenshots

Screenshot_20200807-233203

unverified bug

Most helpful comment

Closing for now.

RadioButton is going through a major change on 5.0.0

11628

Please don't make anything new, just fix the existing functionality. PLEASE!

All 25 comments

Closing for now.

RadioButton is going through a major change on 5.0.0

https://github.com/xamarin/Xamarin.Forms/pull/11628

Oh well...at least there an easy workaround till then - put the RadioButton in a horizontal stack panel along with a label, and optionally add a TapGestureRecognizer to the label so tapping it also sets the radio button value.

for me also radio button not working after updated to 4.8 version of xamarin forms. kindly advise me whether i can use it my real time project or not.
image

@kamalkumar1 The radio button works for me, but does not display a label under Android. So I simply put it in a StackPanel with a normal label and added a TapGestureRecognizer to the label, so that tapping it will check the radio button.

            <StackLayout Orientation="Horizontal">
              <RadioButton Margin="5" Text="Dark theme" IsChecked="{Binding UseDarkTheme}" />
              <Label VerticalOptions="Center" Text="Dark theme" IsVisible="{OnPlatform Android=true, UWP=false}" >
                <Label.GestureRecognizers>
                  <TapGestureRecognizer Tapped="UseDarkTheme_Tapped" />
                </Label.GestureRecognizers>
              </Label>
            </StackLayout>

Closing for now.

RadioButton is going through a major change on 5.0.0

11628

Please don't make anything new, just fix the existing functionality. PLEASE!

so we expect breaking changes every time this make development experience unpleasing cuz when u update to latest version your not sure what will work and what will not work so its a tiresome

@Munde when you use Microsoft products for a long time you get used to it that it breaks something with every release. But yea it's super annoying for a development framework to break multiple things with each release without even fixing all the old releases...

Quick Workaround for the problem:

<StackLayout Orientation="Horizontal">
    <StackLayout.Spacing>
        <OnPlatform x:TypeArguments="x:Double">
            <On Platform="iOS" Value="-8" />
        </OnPlatform>
    </StackLayout.Spacing>

    <RadioButton x:Name="LocalRadioButton" IsChecked="{Binding IsSelected}"
                 GroupName="{Binding Source={x:Reference EntryGrid}, Path=BindingContext.Identifier}" />

    <Label Text="{Binding SelectionText}" FontSize="Default" LineBreakMode="TailTruncation" VerticalOptions="Center">
        <Label.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding ViewModel.ToggleRadioButtonCommand, Source={x:Reference ContentPage}}"
                CommandParameter="{x:Reference LocalRadioButton}" />
        </Label.GestureRecognizers>
    </Label>
</StackLayout>

Yes, I know this increases the VisualTree. Yes, I also know that this requires the ViewModel to reference the RadioButton and do the IsChecked toggle. It's not a clean good solution but at least it is working..

I found this problem too. It's so confusing and tired as a new Xamarin-learner.

@hopeko just get used to it, they do it on a regular basis to break stuff on updates. :D

@Sebastian1989101 I used another way arround using tapGestures but all in all its unpleasant developer experience since i wasted almost 2 hours at first looking for what waswrong withmy code, also on upcoming version there are lot to come on breaking changes am using c# for makeup n we are told its being kicked of xamarin forms so its a trade off to stay with either xf 4.8 or move to 5 when its available there us no smoth transition

This is an interesting bug to be introduced in Xamarin Forms 4.8 if changes that go in completely different direction are being merged in Forms 5.0. It seems odd for 4.8 to completely break on Android if the other ticket is going to be changing things in 5.0.

For Xamarin dev team, no big deal to broke something, but fixing it took a long time. Question, what a hell are you doing???

@samhouts Maybe, it will be easy to fix this bug, not closing it. Whole month you didn't do nothing.

Aarrrggghhhh, just been wasting my time on this one. Lucky I came across it before we accidentally released with this.
I'll try replacing all of our RadioButtons with the ridiculous StackLayout/OnPlatform/TapGesture/Label workaround, thanks @Sebastian1989101

Frustrating.

Try input control availble in nuget packge.

Regard

Kamalkumar.E
Senior Mobile Application Developer
Mobile:+91-9750461689
Skype:kamalelango15
https://www.linkedin.com/in/kamal-kumar-39450654/

On Sat, Oct 3, 2020 at 3:57 PM RhomGit notifications@github.com wrote:

Aarrrggghhhh, just been wasting my time on this one. Lucky I came across
it before we accidentally released with this.
I'll try replacing all of our RadioButtons with the ridiculous
StackLayout/OnPlatform/TapGesture/Label workaround, thanks
@Sebastian1989101 https://github.com/Sebastian1989101

Frustrating.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Xamarin.Forms/issues/11700#issuecomment-703082051,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABXDAFFNT5VOZUS734J47FLSI337NANCNFSM4PYQFOPA
.

Wtf @PureWeen what do you mean close this for now?? It's literally completely broken and a regression bug. What a fucking joke. Experimental does not mean 'non working'. I'm going back to 4.7

Whilst I don't agree with the language I do agree that this has been extremely inconvenient and pretty poor form.

More issues have arisen recently in our latest production build because of this. Now we need to prepare another build because data entry elements of the UI being unusable. My fault really, we generate some UI elements in code not XAML which I missed when doing the original StackLayout/OnPlatform/TapGesture/Label workaround.

I probably won't bother using experimental features again.

I have downloaded XF 5.0 and there is no Text property in RadioButton.
No Text - no bug.
Profit! =)

I have downloaded XF 5.0 and there is no Text property in RadioButton.
No Text - no bug.
Profit! =)

Maybe, just maybe because it has now a Content which can hold everything. See: https://youtu.be/ttF80UnrJAg?t=364

Switching to https://github.com/enisn/Xamarin.Forms.InputKit

I understand the feature was experimental - the issue should not be closed. Radios without labels is a big problem and just closing it does not leave me with much of any confidence.

I have downloaded XF 5.0 and there is no Text property in RadioButton.
No Text - no bug.
Profit! =)

Maybe, just maybe because it has now a Content which can hold everything. See: https://youtu.be/ttF80UnrJAg?t=364

Thanks. I will check this.

I cannot speak to its reliability, but I was able to work around this issue with a custom renderer.

using Android.Content;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(RadioButton), typeof(ProjectName.Droid.Renderers.PatchedRadioButtonRenderer))]
namespace ProjectName.Droid.Renderers
{
    /// <summary>
    /// A workaround for the issue in the in-box renderer.
    /// https://github.com/xamarin/Xamarin.Forms/issues/11700
    /// </summary>
    public class PatchedRadioButtonRenderer : RadioButtonRenderer
    {
        public PatchedRadioButtonRenderer(Context context) : base(context) {}

        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            // Apply text to native radio button
            this.Control.Text = e.NewElement.Text;

            base.OnElementChanged(e);
        }
    }
}

@IgorKravchenko10 there is value i thing replace the text

Classic Xamarin!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

suihanhbr picture suihanhbr  ·  3Comments

simontocknell picture simontocknell  ·  3Comments

Papirosnik picture Papirosnik  ·  3Comments

AppGrate picture AppGrate  ·  3Comments

EmilAlipiev picture EmilAlipiev  ·  3Comments