Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] RadioButton not displaying text on Android #11700

Closed
JogyBlack opened this issue Aug 8, 2020 · 27 comments
Closed

[Bug] RadioButton not displaying text on Android #11700

JogyBlack opened this issue Aug 8, 2020 · 27 comments
Labels
s/unverified New report that has yet to be verified t/bug 🐛

Comments

@JogyBlack
Copy link
Contributor

JogyBlack commented Aug 8, 2020

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

@JogyBlack JogyBlack added s/unverified New report that has yet to be verified t/bug 🐛 labels Aug 8, 2020
@samhouts samhouts added this to New in Triage Aug 8, 2020
@PureWeen
Copy link
Contributor

PureWeen commented Aug 8, 2020

Closing for now.

RadioButton is going through a major change on 5.0.0

#11628

@PureWeen PureWeen closed this as completed Aug 8, 2020
Triage automation moved this from New to Closed Aug 8, 2020
@JogyBlack
Copy link
Contributor Author

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.

@kamalkumar1
Copy link

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

@JogyBlack
Copy link
Contributor Author

@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>

@Tommigun1980
Copy link

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!

@Munde
Copy link

Munde commented Aug 18, 2020

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

@Sebastian1989101
Copy link

@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...

@Sebastian1989101
Copy link

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..

@hopeko
Copy link

hopeko commented Aug 28, 2020

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

@Sebastian1989101
Copy link

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

@Munde
Copy link

Munde commented Aug 28, 2020

@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

@BurkusCat
Copy link
Contributor

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.

@samhouts samhouts removed this from Closed in Triage Sep 8, 2020
@Midnayt
Copy link

Midnayt commented Sep 9, 2020

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

@Midnayt
Copy link

Midnayt commented Sep 9, 2020

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

@RhomGit
Copy link

RhomGit commented Oct 3, 2020

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.

@kamalkumar1
Copy link

kamalkumar1 commented Oct 3, 2020 via email

@ymebrugts
Copy link

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

@RhomGit
Copy link

RhomGit commented Oct 20, 2020

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.

@IgorKravchenko10
Copy link

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

@Sebastian1989101
Copy link

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

@mphill
Copy link

mphill commented Oct 26, 2020

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.

@IgorKravchenko10
Copy link

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.

@Silic0nS0ldier
Copy link

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);
        }
    }
}

@KevinAnass
Copy link

@IgorKravchenko10 there is value i thing replace the text

@ghost
Copy link

ghost commented Nov 17, 2020

Classic Xamarin!

@Hokutosei
Copy link

yep, experiencing this now. no text displaying to radiobutton

@njsokalski
Copy link

Here is a nice Style I created in case anyone wants it:

<Style x:Key="RadioButtonStyle" TargetType="RadioButton"> </Style>

This gave a very basic standard Radio Button. You can obviously modify it any way that is appropriate for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests