0

I have created custom buttons and edittexts, I require them in many activities . I want them all to look the same having a particular design . Normally we set layouts to these widgets by findViewById() but in this case i am adding those edittexts dynamically. I want to know if there is a way i can set layout to my edittext either in the class itself or after it's instantiation ?

Hissaan Ali
  • 2,229
  • 4
  • 25
  • 51
  • It's not very clear what you're asking. "Normally we set layouts to these widgets by `findViewById()`" – The `findViewById()` method is used to locate `View`s with a particular ID in a hierarchy. It's not inherently tied to XML layouts. "I want to know if there is a way i can set layout to my edittext" – What exactly do you mean by that? Do you mean you want to set an ID on your `EditText` that you can use with `findViewById()`? – Mike M. Aug 25 '19 at 08:43
  • I am sorry if i was not clear enough . Let me elaborate what i am trying to do . We set views to their java declaration using findViewById() which points to a particular id in xml file where we have designed our button with properties like padding , margins, background. In my case i have created a created a custom class and i am adding it dynamically to my views . I can't therefore use findViewById to connect it to any view from xml. i was looking for a way to connect it to a view from an xml file so then it's now displayed with all those properties let me know if i need to be more clear – Hissaan Ali Aug 25 '19 at 08:54
  • It sounds like you want to inflate your `View`s from pre-defined layouts – where you've set the desired attributes' values – rather than directly instantiating them with `new`. Is that what you're doing currently? Instantiating with `new`? – Mike M. Aug 25 '19 at 09:00
  • yeah exactyly , currently i am doing that with `new` and i actually want to inflate my view from predefined attributes ! – Hissaan Ali Aug 25 '19 at 09:02
  • Kinda like this, then? https://stackoverflow.com/a/38012476 – Mike M. Aug 25 '19 at 09:04

0 Answers0