开发者

Reusing an XML component, changing only one text field

开发者 https://www.devze.com 2023-03-31 04:36 出处:网络
I have a XML component composed by an ImageView and a TextVi开发者_如何转开发ew. I\'m including this component a couple times in other XML codes. I\'m wondering if theres some way to have different te

I have a XML component composed by an ImageView and a TextVi开发者_如何转开发ew. I'm including this component a couple times in other XML codes. I'm wondering if theres some way to have different texts every time I include the mentioned component only using XML, without having to do this programmatically. Any clues?

Thanks!


I'm sorry, but XML, much like HTML, is static. Making it dynamic involves code.

So, if you really, really, really want to do this, you'd have to extend a TextView object with code. It would set it's own text dynamically by pulling from an array or database or whatever. After doing this, you can place your special TextView objects in any XML file that you want.

Example of extending TextView.

However, after going through that much effort. It may just be easier to make a for loop that finds all of your TextViews and calls setText().


yes, it is possible. You would need to call TextView.setText().

leave a comment with more details if this isn't the answer your looking for.

Updated:

The best way to do this is through code. its by far the easiest

0

精彩评论

暂无评论...
验证码 换一张
取 消