Writing custom views for android - studentuhelp.ru

Creating custom and compound Views in Android - Tutorial

LinearLayout xmlns:android"m/apk/res/android" android:id id/list_item_type1_layout" android:layout_width"match_parent" android:layout_height"match_parent" android:orientation"vertical" TextView android:id id/list_item_type1_text_view" android:layout_width"wrap_content" android:layout_height"wrap_content" android:text"Text goes here" / /LinearLayout list_item_type2.xml:?xml version"1.0" encoding"utf-8"? LinearLayout xmlns:android"m/apk/res/android" android:id id/list_item_type2_layout" android:layout_width"match_parent" android:layout_height"match_parent" android:orientation"vertical" Button android:id id/list_item_type2_button" android:layout_width"wrap_content" android:layout_height"wrap_content" android:text"Button text goes here" / /LinearLayout). OnAttachedToWindow mDraweeHolder. OnAttach @Override public void onFinishTemporaryDetach super. OnFinishTemporaryDetach mDraweeHolder. OnAttach Handling touch events If you have enabled tap to retry in your Drawee, it will not work unless you tell it that the user has touched the screen. We provide two alternative classes you can use to host your Drawee: DraweeHolder for a single image, multiDraweeHolder for multiple images, draweeHolder is a class that holds one DraweeHierarchy and the associated DraweeController.

Set. Build mMultiDraweeHolder new MultiDraweeHolder GenericDraweeHierarchy mMultiDraweeHolder. Add ( new DraweeHolder GenericDraweeHierarchy ( hierarchy, context / repeat for more hierarchies You must override system events, set bounds, and do all the same responsibilities as for a single DraweeHolder).

It allows you to make use of all the functionality Drawee provides in your custom views and other places where you need a drawable instead of a view. To get the drawable, you just do tTopLevelDrawable. Handling attach/detach events, your app may leak memory if this steps are not followed. There is no point in images staying in memory when Android is no longer displaying the view - it may have scrolled off-screen, or otherwise not be drawing. The getItemView method checks to see which list items should be type 1 or type 2. According to my static ints I defined up top, the first 5 list items will be list item type 1, and the last 5 list items will be list item type 2.

So if you compile and run this, you will have a ListView that has five items that just contain a Button, and then five items that just contain a TextView. Below is the Activity code, the activity xml file, and an xml file for each list item type.