[android-developers] Re: Handling a layout ...
Sorry about the late response. Here's what I meant by the potential casting problem; In order to add the ImageView variable, which was created to handle the Drawable resource, you need to cast the parent layout, which is of type ImageView, to ViewGroup type if you're planning to use the addView() method. I've tried this already and got into trouble with the casting ... I guess it's because ViewGroup is an abstract class. Emre Date: Sat, 25 Jul 2009 11:52:53 -0400 From: mmur...@commonsware.com To: android-developers@googlegroups.com Subject: [android-developers] Re: Handling a layout ... Emre A. Yavuz wrote: You can, but then the child is already added to the parent; you do not need to add it yourself. I agree with you, but if you're not going to store this info in the layout, the only option left seem to be refering it using its R.drawable.childview. R.drawable.childview is a references to a Drawable resource (res/drawable) and is not a reference to a View in a layout. How can you convert this, an integer, to a View then ? Should I create an ImageView variable and use its setImageresource() method ? Yes. Then you need to add that to some parent layout via addView() as previously described. but will there be a casting problem in that case ? I do not understand this question. The DDMS perspective in Eclipse doesn't tell me anything at all. I get a message from the emulator saying that the application has stopped working. The DDMS perspective contains a panel(?) called LogCat, which will give you a stack trace when an exception occurs. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! _ Stay in the loop and chat with friends, right from your inbox! http://go.microsoft.com/?linkid=9671354 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Handling a layout ...
Emre A. Yavuz wrote: Sorry about the late response. Here's what I meant by the potential casting problem; In order to add the ImageView variable, which was created to handle the Drawable resource, you need to cast the parent layout, which is of type ImageView, to ViewGroup type if you're planning to use the addView() method. You cannot add an ImageView to an ImageView. ImageView is not a container and, therefore, is not a ViewGroup. You can only add Views (e.g., ImageView) to a ViewGroup (e.g., LinearLayout). However, I cannot imagine a GUI design that would require an ImageView hold another ImageView. For example, if your goal is to replace an image in an ImageView, you can just call setImageResource() on the ImageView you already have, rather than try adding a new one. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Need Android talent? Ask on HADO! http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Handling a layout ...
What if you try to add (and by adding I mean placing on top of it) an ImageView to another one ? Say you've already set the image in your layout xml file and later on you'd like place a smaller image somewhere on it in order it to be used as a button to click on. Emre Date: Thu, 30 Jul 2009 07:20:21 -0400 From: mmur...@commonsware.com To: android-developers@googlegroups.com Subject: [android-developers] Re: Handling a layout ... Emre A. Yavuz wrote: Sorry about the late response. Here's what I meant by the potential casting problem; In order to add the ImageView variable, which was created to handle the Drawable resource, you need to cast the parent layout, which is of type ImageView, to ViewGroup type if you're planning to use the addView() method. You cannot add an ImageView to an ImageView. ImageView is not a container and, therefore, is not a ViewGroup. You can only add Views (e.g., ImageView) to a ViewGroup (e.g., LinearLayout). However, I cannot imagine a GUI design that would require an ImageView hold another ImageView. For example, if your goal is to replace an image in an ImageView, you can just call setImageResource() on the ImageView you already have, rather than try adding a new one. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Need Android talent? Ask on HADO! http://wiki.andmob.org/hado _ More storage. Better anti-spam and antivirus protection. Hotmail makes it simple. http://go.microsoft.com/?linkid=9671357 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Handling a layout ...
Mark, You can, but then the child is already added to the parent; you do not need to add it yourself. I agree with you, but if you're not going to store this info in the layout, the only option left seem to be refering it using its R.drawable.childview. How can you convert this, an integer, to a View then ? Should I create an ImageView variable and use its setImageresource() method ? I have just thought of this now and I haven't tried it yet, but will there be a casting problem in that case ? The DDMS perspective in Eclipse doesn't tell me anything at all. I get a message from the emulator saying that the application has stopped working. Emre Date: Fri, 24 Jul 2009 19:41:21 -0400 From: mmur...@commonsware.com To: eayl...@hotmail.com Subject: Re: [android-developers] Re: Handling a layout ... You appear to have written to me directly by accident. Please keep threads like this on-list, for the benefit of others. Emre A. Yavuz wrote: I was using findViewById() to get the layout which I wanted to modify and casting it to type ImageView afterward. However, you need to cast it to ViewGroup if you want to call addView() which means you need to update your code to cast it to ViewGroup instead. Correct. The problem occurs when you call addView() to add the child view to the parent you want to modify. Don't you store the child view in your layout file under the handler for the parent view ? You can, but then the child is already added to the parent; you do not need to add it yourself. The code seems to crash when it tries to add the child view read by findViewById()method. You need to look at the Java stack trace, to see the error message and where it occurred. The stack trace is in LogCat, accessible via adb logcat, DDMS, or the DDMS perspective in Eclipse. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Looking for Android opportunities? http://wiki.andmob.org/hado _ More storage. Better anti-spam and antivirus protection. Hotmail makes it simple. http://go.microsoft.com/?linkid=9671357 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Handling a layout ...
Emre A. Yavuz wrote: You can, but then the child is already added to the parent; you do not need to add it yourself. I agree with you, but if you're not going to store this info in the layout, the only option left seem to be refering it using its R.drawable.childview. R.drawable.childview is a references to a Drawable resource (res/drawable) and is not a reference to a View in a layout. How can you convert this, an integer, to a View then ? Should I create an ImageView variable and use its setImageresource() method ? Yes. Then you need to add that to some parent layout via addView() as previously described. but will there be a casting problem in that case ? I do not understand this question. The DDMS perspective in Eclipse doesn't tell me anything at all. I get a message from the emulator saying that the application has stopped working. The DDMS perspective contains a panel(?) called LogCat, which will give you a stack trace when an exception occurs. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Handling a layout ...
Emre A. Yavuz wrote: Hi all, Does somebody know how to handle a specific layout (say LinearLayout), which was given in a XML layout file, previously set in the Activity class using a SetContentView () method ? I am trying to add an image (probably as a child) to a previously set layout. Step #1: Use findViewById() to get the layout you want to modify, casting it to the appropriate type. Step #2: Call addView() on that layout with the widget you wish to add, specifying the appropriate type of LayoutParams (e.g., LinearLayout.LayoutParams, RelativeLayout.LayoutParams). Step #3: There is no step #3. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---