How to optimize the listview int android? -
In my list view, each item contains some textviews and images, they are defined in the XML layout file
Viewholder Contributor; If (convertView == faucet) {convertView = LayoutInflater.from (mContext) .inflate (R.layout.vw_system_notice_list_item, tap); But they can show some pictures of different types, nothing is now being examined in getView method:
if (TextUtil.isEmpty (SystemMessage.image)) {viewHolder.img.setVisibility (see GONE); } And {viewHolder.img.setVisibility (see Visual.); } I am thinking, I have created some useless image objects, then set visibility (see genes) . How do I optimize memory or list view?
two solutions,
- You've already done this, hide Hide on the basis of scenario.
-
For this, a little extra effort will be required.
a. First create and use an adapter
getViewTypeCount (): - Here you will return the number of your list support, such as in your case there are two different layouts with images and text views, and image view Without other
getItemViewType: - Here you will have to check this special situation to see what the child's layout should be.
Once done, you only need a little extra code in your adapter's getView method, here's a sample code, which you have to expand for yourself, besides, This two, I do not think you have no choice unless you expand the assellistview and make yourself one according to your own needs.
Class CustomAdapter BaseAdapter Expanded {@Override public int getCount () {// TODO Auto generated method stub return 0; } @OverWide Public Object Hot Itam (Int Position) {// TODO Auto-generated method stub returns empty; } @ Override Public Long ITMID (Int Position) {// Tudo Auto-Generated Method Stub Return 0; } @ Override Public View getView (int position, seeviewview, ViewGroup Parent) {// You get the type type you want for this type of type = getItemViewType (status); If (convertView == faucet) switch (type) {// fill, populate and return different visual types from here} Return tap; } @ Override Public Intimate Typecount () {// Return the number of different ideas here which you have super. GetViewTypeCount (); } @ Override Public Int ITEM ViewType {// Here you want to use this type of scene, super.getItemViewType (status) for returning to this situation; }} Atlamat hooked this adapter into your list and enjoyed it !! For more information, I think you can see this link [http://android.amberfog.com/?p=296][1]
Comments
Post a Comment