Yes I agree Bob. In this case it would require a whole lot of refactoring for a minor adjustment. All I really need to do is capture a bunch of style attributes that are used later in some custom drawing. Fastest way from A to B is to simply know which resource was loaded.
I have to say, I'm surprised that the View doesn't know who loaded it, or that the tag is not available (null tag a consider a bug). - Brill Pappin On Jan 13, 7:19 pm, Bob Kerns <[email protected]> wrote: > It seems to me the problem is that you're trying to do initialization > in a constructor. That is extremely limiting. > > Try doing whatever your doing in a more appropriate place -- later. > onFinishInflate() would seem a likely candidate for your purposes. But > you could also consider doing it at the point of first use of whatever > you're doing. > > Of course, depending on how the views do their thing, you may have to > repeat some style handling that may already have been done during the > inflation process. But that really shouldn't happen IMO (guessing > wildly here at how things work). That really should be happening no > earlier than in the super.onFinishInflate() -- so consider that some > of your processing may want to happen before the > super.onFinishInflate(), to supply updated information to any code > that runs there, and some may want to happen after the > super.onFinishInflate(), to override whatever was done there. > > Of course, there could be processing you need to override that happens > even later. But at least by onFinishInflate(), you'll have access to > any tag or custom attribute. > > Of course, you could try getting your information yourself directly > from the AttributeSet that is supplied to the constructor, but I > really think the constructor is the wrong place to be customizing. > > On Jan 13, 11:04 am, Brill Pappin <[email protected]> wrote: > > > > > > > > > I can't set it after inflate because I'm trying to access it in the > > constructor. > > > I did try setting it in xml, but I only get null back (may be a bug, but I > > haven't investigated that). > > > - Brill Pappin > > > Sent from my Android device > > > Brad Gies <[email protected]> wrote: > > > >Can't you just set the tag when you inflate it? Or set the tag in the > > >.xml file? > > > >Sincerely, > > > >Brad Gies > > >----------------------------------------------------------------------- > > >Bistro Bot - Bistro Blurb > > >http://bgies.com http://nocrappyapps.com > > >http://bistroblurb.com http://forcethetruth.com > > >http://ihottonight.com > > >----------------------------------------------------------------------- > > >Everything in moderation, including abstinence (paraphrased) > > > >Every person is born with a brain... Those who use it well are the > > >successful happy ones - Brad Gies > > > >Adversity can make or break you... It's your choice... Choose wisely - > > >Brad Gies > > > >Never doubt that a small group of thoughtful, committed people can > > >change the world. Indeed. It is the only thing that ever has - Margaret > > >Mead > > > >On 13/01/2011 10:28 AM, Brill Pappin wrote: > > >> Ok, this is the same problem as my last post, but i'm not getting any > > >> traction with it, so i'm looking for another method solve the problem. > > > >> All i need to do is identify the xml resource a view was inflated > > >> from, in the views constructor. > > > >> I've tried android:tag which does not seem to be able to do it in this > > >> case (I only ever get null back from getTag()). > > > >> The situation is that I have a single java class extending view. > > >> I inflate one of many XMLs into the view and I need to be able to > > >> change stylesheets based upon which xml resource i'm loading. > > > >> Does anyway one a method of doing this? > > > >> My last fallback is to use some sort of static class that I can set > > >> the xml resource on for the entire app, then try and look at the id to > > >> determine which resource I loaded. I'm reluctant to do that because > > >> it's kludgy and I think its far more likely to introduce bug etc. Note > > >> that I haven't tried to do this yet, but it should work based on how > > >> java behaves. > > > >> I just can't believe that there is no way to a view to know what XML > > >> resource it was inflated from! > > > >> - Brill Pappin > > >> -- > > >> You received this message because you are subscribed to the Google > > >> Groups "Android Developers" group. > > >> To post to this group, send email to [email protected] > > >> To unsubscribe from this group, send email to > > >> [email protected] > > >> For more options, visit this group at > > >>http://groups.google.com/group/android-developers?hl=en > > > >-- > > >You received this message because you are subscribed to the Google > > >Groups "Android Developers" group. > > >To post to this group, send email to [email protected] > > >To unsubscribe from this group, send email to > > >[email protected] > > >For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

