android - How to create xml's id?
Asked Answered
Y

3

32

I'm developing a dynamic keyboard application using soft keyboard sample. My application changes layout. For example I have a keyboard(has one key) then I set up the app and I can use keyboard(has one key).

I want to create an XML file after compilation and use this file in the application (reading XML file with xmlpullparser or xmlresourceparser). However, keyboard class needs XML's id. How do I create an XML id?

Yearbook answered 10/4, 2012 at 18:1 Comment(0)
C
61

It can be defined in ids.xml or any custom file like constants.xml inside your res\values folder.

Examples:

<resources>
    <item type="id" name="keyboard" />
</resources>

and can be accessed in the code as following:

R.id.keyboard 
Cargill answered 19/3, 2013 at 11:53 Comment(1)
I get the error found tag id where item is expected when using the first methodIllhumored
F
24

You can define ids using an ids.xml file in your res/values directory. Here's an example:

<resources>
    <item type="id" name="my_keyboard" />
</resources>

In code, you would set the id like so:

keyboardView.setId( R.id.my_keyboard );
Falconiform answered 10/4, 2012 at 18:12 Comment(3)
Is your answer set id for keyboardView?Yearbook
You're asking how to create resource IDs for XML elements, right? Or did I misunderstand.Falconiform
see here: developer.android.com/samples/ActionBarCompat-Basic/res/values/…Sottish
D
2

XML files are compiled (binary XML) and thus you don't create them at runtime.

If you want to change your keyboard layout dynamically, you'll do that programmatically rather than in XML.

Damnable answered 10/4, 2012 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.