I want to create a subclass of Gallery, but I don’t know any way to
instantiate a variable of such a subclass using findViewById().
Proposed code:
Public class MyGallery extends Gallery{
Public MyGallery(Context ctx, AttributeSet attrSet) { // code for
constructor }
// more code for subclass
}
MyGallery myGallery = (Gallery) findViewById(R.id.gallery); // but
this doesn’t work…
MyGallery myGallery = (MyGallery) findViewById(R.id.gallery); // and
this doesn’t work…
However, MyGallery can use super() constructors. So if I can
instantiate a Gallery variable using constructors (such as Gallery
gallery = new Gallery(this, attribSet)) which would give me a Gallery
view which is equivalent to the one created with findViewById(), that
might be workable! This assumes that it is even possible to get the
same gallery view using a constructor with “attribSet” as the gallery
view obtained by using the findViewById() method. Does anyone know
if that is possible? If so, how do I go about getting the correct
attribSet so I get a gallery which looks like the one instantiated
with findViewById()?
If it is possible, simplistically, I would like to do:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
MyGallery myGallery = new MyGallery(this, gallery.someMethodToGetAttSet
());
However, I can’t find any methods in Gallery which will return its
attribSet. Do I need to use an XML parser to parse the R.id.gallery
myself? The info I found in the API regarding
android.utl.AttributeSet is relatively brief, and I don’t understand
it well. However, it seems that AttributeSet recommends using
Resources.Theme.obtainStyledAttributes() but the API is even briefer
on this, and I don’t understand: 1) how obtainStyledAttributes() which
returns a TypedArray helps me with getting an AttributeSet and 2)
since obtainStyledAttributes() requires an AttributeSet parameter
(which is what I was trying to get in the first place), where am I
supposed to get that? I have tried googling but can’t seem to get any
more detailed instruction on this.
Does anyone know where I might find help in this regard?
Thanks
Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---