Creating dynamic controls
I am trying to create a screen with some dynamic controls, well radio buttons to be precise purely for learning purposes.
I have managed to add the radio button by referencing the radio group in the main.xml file.
RadioGroup rg = (RadioGroup)findViewById(R.Id.types);
RadioButton rb = new RadioButton(this);
rb.setText("some text!");
rg.addView(rb);
What I cannot figure out is how do I set the id of the radio button?
If use rb.setId() it wants an integer? I am trying to basicaly do the xml bit dynamically:
Asked by: Agata697 | Posted: 20-01-2022
Answer 1
rb.setId(int) is how you would set the ID. You say "it wants an integer?" as if you find that strange. All View IDs are integers so what else would you expect?
Answered by: Clark328 | Posted: 21-02-2022Answer 2
well if you set it in the xml file as
The yadda appears in the R.java file as an autogenerated number. Therefore I was not sure that it was correct to assign any old number seeing as you pass text in the xml.
Answered by: Ted563 | Posted: 21-02-2022Similar questions
Creating customs controls in Android
I want to create my own custom controls in Android application and use them in this way:
In the XML file:
<MyButton .... />
I would like to define MyButton some where in the resources XML
android - Creating custom controls
I am coming from a Microsoft world so maybe a stupid question.
In UWP you can create a Custom control with public properties type of object, then define XAML for the Custom control where you layout elements - for example render the content of the objects in a grid rows, and you will end up with a reusable layout and you can reuse it in other places like so:
<CustomLayoutControl>
<CustomLao...
Android SDK Error Upon Creating Emulator
I am running into a problem creating an android emulator from the command line. When I run the android command the messages below output.
Starting Android SDK and AVD Manager
SWT folder 'lib\x86_64' does not exist
Please set ANDROID_SWT to point to the folder containing swt.jar for platform
I've already:
Execute SDK Setup.exe and brought ...
android - Problem creating AVD
I have installed Android SDK on my MAC OS X 10.6 and facing lots of problem while creating AVD.
When I tried to create it for ECLIPSE (3.5 Gallelio) then after clicking the 'new' button, when I try to type a name there comes a message bellow saying 'a target must be selected in order to create an AVD'. But the problem is, the Target field is deactivated.
If I'm trying to create AVD from terminal wit...
java - Creating database in android
i was creating a database and deleting it, adding registries on my android htc mobile sqlite database without any problem.
But now, after last deleting of the database everytime i want to create a new one i get a sqlite exception that says me "unable to open database file" with the following data:
serialVersionUID (RuntimeException)= -7034897190745766939
cause= SQLiteException (id=830...
Creating an empty Drawable in Android
Creating a Drawable that is completely empty seems like a common need, as a place holder, initial state, etc., but there doesn't seem to be a good way to do this... at least in XML. Several places refer to the system resource @android:drawable/empty but as far as I can tell (i.e., it's not in the reference docs, and aapt chokes saying that it can't find the resource) this doesn't exist.
Is there a gene...
android - Issue creating AVD on command prompt in windows XP
I am the beginner for android development. I followed the procedure as specified in developer.google.com . for installing I Tried to create AVD(Android virtual device) through command path. I executed at command prompt.
android create avd --target 2 --name my_avd
But the Error is coming "Error: Target id is not valid. Use 'android.bat list targets' to get the target ids."...
Creating an image of an Android phone
Does anyone know how to create a 1:1 disk image of an Android phone? I am taking a forensics course and our final project involves creating tools to recover information from a suspect's Android based phone, however to do this we need to be able to create a 1:1 image of the phone's disk for baseline comparisons. Also would the image be loadable into AVD?
android - Creating a Custom Compound Button Bar
I have to create a custom compound button bar control in Android like the one here. To create a button bar like this, I am thinking of extending a LinearLayout and add my buttons to it. The buttons have a black background but with a gradient fill; I am not keen on using PNGs since the color of the ...
java - Creating a list of integers in XML for android
I would like to create a list of Integers in the /res folder of an android project. However, I want those integers to point resources in /res/raw. So for example, I would like something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="built_in_sounds">
<item>@raw/sound</item>
</integer-array>
</resources&g...
shell - Creating folders using Android SDK
Is it possible to be able to create a folder on the sd card of the phone via using Android SDK or the Shell?
Creating a dynamic (video) Overlay on Google Maps on Android 2.1
I'm trying to create a map overlay for displaying a video stream (MJPEG) on top of a Mapview.
Currently I've a standalone activity that creates a data thread for fetching MJPEG video frames. I'm using a handler to send a frame (as a Bitmap) from the data thread to the main activity which then updates the UI.
I'm not sure how to implement "refresh" for updating my "overlayed" video stream.
EDIT: ...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android