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.

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

Top

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);
rb.setText(s);



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

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests