-1

I am working on Xamarin Android using C#. I have a XML containing the list of values which I would like to show as radio buttons. These buttons have to be created dynamically. Am unable to do so. Though Xamarin says that they support HTML tags as well but even that is not working.

halfer
  • 19,824
  • 17
  • 99
  • 186
AISPL
  • 11
  • 2

1 Answers1

1

Τake a look at this answer by Charlie Collins, on how to create a UI Elements from HTML

I know this example isn't using a Button, but it's the same idea

String needs to be a resource:

<?xml version="1.0" encoding="utf-8"?>
        <resources>
        <string name="mystring">    
            You can use regular text, and escaped HTML markup
            &lt;br /&gt;&lt;br /&gt;
            A simple BOLD example &lt;b&gt;StackOverflow&lt;/b&gt;.
        </string>
        </resources>

Then get the resource and use Html.fromHtml() (if you are using an EditText, you also need to make sure the buffer is set to SPANNABLE):

     public class MyActivity extends Activity {
        TextView myTextView;

           @Override
           public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.about);     

              myTextView = (TextView) this.findViewById(R.id.mytextview);
              myTextView.setText(Html.fromHtml(getResources().getString(R.string.mystring)),
                                 TextView.BufferType.SPANNABLE);
           }  
           ...

Lastly, note that all HTML doesn't work, of course. So depending on your requirements, this might not be entirely useful.

Community
  • 1
  • 1
iamIcarus
  • 1,428
  • 11
  • 28
  • @iamlcarus: Please take note of the formatting improvements I've made to your post, and how I've corrected cited your source. Also take note on [this ongoing meta discussion](http://meta.stackoverflow.com/questions/285349/how-to-handle-answers-which-copy-its-whole-content-from-another-answer-with-prop), as to whether answers which are nothing more than copied content are acceptable. – Matt Jul 09 '15 at 17:14