Dynamic text to radio button

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Dynamic text to radio button

Postby Encryption » Tue Oct 05, 2010 1:01 am

Working on a DB based application but I've hit a stumbling block on implementation. I have string data stored that I need to use to populate 4 radio buttons with text. I would like to grab this data from the database at random, and display the text as the radio button text.

I'm kind of stumped as to how to get this done. Obviously I won't be using the strings.xml for the radio buttons as the text has to come from the database. What's the best way to get this done programmaticly? I haven't expieremented with setting text during run time in the main class. So far I've only used the string.xml for such objects.

any advice is greatly appreciated.

Once Poster
Once Poster
Posts: 1
Joined: Tue Oct 05, 2010 12:52 am


Re: Dynamic text to radio button

Postby visivi » Mon Nov 01, 2010 4:05 pm

this is quite done quite easily.
Depending on how you implemented the four radiobuttons (i'm going with defined in the layout).
Code: Select all

String s = "your data from database here";

RadioButton rb = (RadioButton)findViewById(R.id.radio1);

It wasn't clear to me if you needed the implementation for the DB-query aswell, so i left that one out.
Posts: 29
Joined: Mon Nov 01, 2010 3:59 pm


Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests