Posts

Showing posts from September, 2017

The Set Interface : java collection interface that guarantees no duplicates as well as preservation of insertion order

The Java platform contains three general purpose  Set  implementations:  HashSet ,  TreeSet , and  LinkedHashSet .  HashSet , which stores its elements in a hash table, is the best-performing implementation; however it makes no guarantees concerning the order of iteration.  TreeSet , which stores its elements in a red-black tree, orders its elements based on their values; it is substantially slower than  HashSet . LinkedHashSet , which is implemented as a hash table with a linked list running through it, orders its elements based on the order in which they were inserted into the set (insertion-order).  LinkedHashSet spares its clients from the unspecified, generally chaotic ordering provided by  HashSet  at a cost that is only slightly higher. You could try to build it by combining  Set  and  List . Any collection implementing  Set  should not allow duplicate elements, and any collection implementing  List  should maintain order.

What is the purpose of Android's tag in XML layouts?

<merge/>  is useful because it can get rid of unneeded ViewGroups, i.e. layouts that are simply used to wrap other views and serve no purpose themselves. For example, if you were to  <include/>  a layout from another file without using merge, the two files might look something like this: layout1.xml: <FrameLayout> <include layout = "@layout/layout2" /> </FrameLayout> layout2.xml: <FrameLayout> <TextView /> </FrameLayout> which is functionally equivalent to this single layout: <FrameLayout> <FrameLayout> <TextView /> </FrameLayout> </FrameLayout> That FrameLayout in layout2.xml may not be useful.  <merge/>  helps get rid of it. Here's what it looks like using merge (layout1.xml doesn't change): layout2.xml: <merge> <TextView /> </merge> This is functionally equivalent to this layout: <FrameLayout> <Te

Cannot be cast to android.view.ViewGroup

 java.lang.ClassCastException: com.philips.platform.lumea.firsttreatmentflow.treatmentstart.StartControllerView cannot be cast to android.view.ViewGroup You can group Views, but you need to use a ViewGroup not a View. Examples of ViewGroups are LinearLayout (for displaying sub-Views horizontally or vertically), RelativeLayout (for displaying sub-Views using relative positions), FrameLayout, TableLayout etc. Use whichever ViewGroup suits your needs. To get something working, change the two Views in your XML to FrameLayouts. And also give the Button and TextView layout parameters (e.g. android:layout_width="wrap_content", same for height) - otherwise you'll get another error when you run it.