• ## GridView 布局:item设置的高度和宽度不起作用、自动适配列数、添加Header和Footer ##


    一、item设置的高度和宽度不起作用

    转自:http://www.cnblogs.com/0616--ataozhijia/p/6031875.html

    [Android Pro] listView和GridView的item设置的高度和宽度不起作用

     

    referece to : http://blog.csdn.net/beibeixiao/article/details/9032569

    1.     在Android开发中会发现,有时listView和GridView的item顶层布局不起作用,即不能设置高度和宽度

            原因是当用自定义的adapter时,如果使用convertView= mInflater.inflate(R.layout.material_grid_item, null)

    方法就不会起作用,这个 方法的第二个参数是父View,传入为空,所以没有加载顶层布局,此时如果使用

    convertView= mInflater.inflate(R.layout.material_grid_item, parent,false);传入parent设置的高度和宽度就会起作用了。

    二、自动适配列数

    转自:http://blog.csdn.net/archer_zoro/article/details/43500389

    写了一个展示多张图片的gridview(几乎每个listview里面都有一个gridview)

    之前用auto_fit和设置列宽来控制列数,以达到自适应的目的。

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. this.setNumColumns(GridView.AUTO_FIT);  
    2. this.setColumnWidth(getResources().getDimensionPixelSize(R.dimen.item_image_size));  
    3. this.setHorizontalSpacing(getResources().getDimensionPixelSize(R.dimen.item_image_spacing));  
    4. this.setVerticalSpacing(getResources().getDimensionPixelSize(R.dimen.item_image_spacing));  

    这样的效果就是图片宽度最小为item_image_size,会在接近这个大小的情况下,自动调整一些大小将gridview占满,间隔不变。3列。

    而后来在720p以上的手机上运行时,变成了4列,但是要求是3列,于是我把列数从auto_fit改成了3,依然是上面的显示效果,

    但是,在滑动listview的过程中明显比刚才卡顿了,所以有改回了auto_fit,转而把item_image_size增大了。

    原理不清楚,留下这个坑待研究

    转自:http://blog.csdn.net/maizangxiangwang/article/details/50913900


    /**
    * 获取屏幕宽度 */ public static int getScreenWidth(Context context) { WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); return display.getWidth(); } public static int dipToPx(Context context, int dip) { if(density <= 0.0F) { density = context.getResources().getDisplayMetrics().density; } return (int)((float)dip * density + 0.5F); }

    给gridview子项要屏幕适配,子项item宽度,高度与宽度相同

    itemWidth = (getScreenWidth(this)-(3*dipToPx(this, 3)))/2;

    在gridview的adapter中的getview中设置子项的参数

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler;
        String url = blogAlbumList.get(position).getAlbumUrl();
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.celebrity_item, null);
            viewHodler = new ViewHodler();
            viewHodler.iv_image = (ImageView) convertView.findViewById(R.id.iv_image);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }
        // if (viewHodler.iv_image.getTag()!=url ||viewHodler.iv_image.getTag()==null) {
        ImageTools.getImageLoader().displayImage(blogAlbumList.get(position).getAlbumUrl(), viewHodler.iv_image, mDisplayImageOptions);
        // viewHodler.iv_image.setTag(url);
        // }
        AbsListView.LayoutParams param = new AbsListView.LayoutParams(LeoApplication.itemWidth, LeoApplication.itemWidth);
        convertView.setLayoutParams(param);
        return convertView;
    }

    其实gridview有个属性.Android:stretchMode=”columnWidth"//缩放与列宽大小同步

    GridView的一些特殊属性:

     

    1.android:numColumns=”auto_fit   //GridView的列数设置为自动

    2.android:columnWidth=”90dp "       //每列的宽度,也就是Item的宽度

    3.android:stretchMode=”columnWidth"//缩放与列宽大小同步

    4.android:verticalSpacing=”10dp”          //两行之间的边距

    5.android:horizontalSpacing=”10dp”      //两列之间的边距 

    6.android:cacheColorHint="#00000000" //去除拖动时默认的黑色背景

    7.android:listSelector="#00000000"        //去除选中时的黄色底色

    8.android:scrollbars="none"                   //隐藏GridView的滚动条

    9.android:fadeScrollbars="true"             //设置为true就可以实现滚动条的自动隐藏和显示

    10.android:fastScrollEnabled="true"      //GridView出现快速滚动的按钮(至少滚动4页才会显示)

    11.android:fadingEdge="none"                //GridView衰落(褪去)边缘颜色为空,缺省值是vertical。(可以理解为上下边缘的提示色)

    12.android:fadingEdgeLength="10dip"   //定义的衰落(褪去)边缘的长度

    13.android:stackFromBottom="true"       //设置为true时,你做好的列表就会显示你列表的最下面

    14.android:transcriptMode="alwaysScroll" //当你动态添加数据时,列表将自动往下滚动最新的条目可以自动滚动到可视范围内

    15.android:drawSelectorOnTop="false"  //点击某条记录不放,颜色会在记录的后面成为背景色,内容的文字可见(缺省为false)

    三、添加Header和Footer

    转自:http://blog.csdn.net/zhzhyang0313/article/details/39163735

    实现这个功能一般有两种思路,一种思路是使用ScrollView+GridView,第二种思路是使用ListView来实现GridView的效果。

    第一种思路的具体实现是把HeaderView和GridView都放到ScrollView里面,这里要解决的问题是ScrollView和GridView滑动手势的冲突问题,解决办法是让GridView充满ScrollView,不让GridView滑动而只让ScrollView滑动。具题做法是重载GridView的onMeasure()方法。

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. public class MyGridView extends GridView {   
    2.     public MyGridView(Context context, AttributeSet attrs) {   
    3.         super(context, attrs);   
    4.     }   
    5.   
    6.     public MyGridView(Context context) {   
    7.         super(context);   
    8.     }   
    9.   
    10.     public MyGridView(Context context, AttributeSet attrs, int defStyle) {   
    11.         super(context, attrs, defStyle);   
    12.     }   
    13.   
    14.     @Override   
    15.     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {   
    16.   
    17.         int expandSpec = MeasureSpec.makeMeasureSpec(   
    18.                 Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);   
    19.         super.onMeasure(widthMeasureSpec, expandSpec);   
    20.     }   
    21. }   

    这种方法的不足是GridView中的View没有复用,如果内容较多将比较消耗内存。

    第二种思路的具体实现是使用ListView的addHeaderView()来添加HeaderView,而ListView的每一行都放一个LinearLayout来保存一行的item,这里要注意的是item的个数和ListView行数的关系。

    后来在StackOverFlow上又看到了第三中方法。原来Google已经用GridView实现了,而且很巧妙,下面把代码贴出来

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. /* 
    2.  * Copyright (C) 2013 The Android Open Source Project 
    3.  * 
    4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
    5.  * you may not use this file except in compliance with the License. 
    6.  * You may obtain a copy of the License at 
    7.  * 
    8.  *      http://www.apache.org/licenses/LICENSE-2.0 
    9.  * 
    10.  * Unless required by applicable law or agreed to in writing, software 
    11.  * distributed under the License is distributed on an "AS IS" BASIS, 
    12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    13.  * See the License for the specific language governing permissions and 
    14.  * limitations under the License. 
    15.  */  
    16. package com.android.photos.views;  
    17. import android.content.Context;  
    18. import android.database.DataSetObservable;  
    19. import android.database.DataSetObserver;  
    20. import android.util.AttributeSet;  
    21. import android.view.View;  
    22. import android.view.ViewGroup;  
    23. import android.widget.AdapterView;  
    24. import android.widget.Filter;  
    25. import android.widget.Filterable;  
    26. import android.widget.FrameLayout;  
    27. import android.widget.GridView;  
    28. import android.widget.ListAdapter;  
    29. import android.widget.WrapperListAdapter;  
    30. import java.util.ArrayList;  
    31. /** 
    32.  * A {@link GridView} that supports adding header rows in a 
    33.  * very similar way to {@link ListView}. 
    34.  * See {@link HeaderGridView#addHeaderView(View, Object, boolean)} 
    35.  */  
    36. public class HeaderGridView extends GridView {  
    37.     private static final String TAG = "HeaderGridView";  
    38.     /** 
    39.      * A class that represents a fixed view in a list, for example a header at the top 
    40.      * or a footer at the bottom. 
    41.      */  
    42.     private static class FixedViewInfo {  
    43.         /** The view to add to the grid */  
    44.         public View view;  
    45.         public ViewGroup viewContainer;  
    46.         /** The data backing the view. This is returned from {@link ListAdapter#getItem(int)}. */  
    47.         public Object data;  
    48.         /** <code>true</code> if the fixed view should be selectable in the grid */  
    49.         public boolean isSelectable;  
    50.     }  
    51.     private ArrayList<FixedViewInfo> mHeaderViewInfos = new ArrayList<FixedViewInfo>();  
    52.     private void initHeaderGridView() {  
    53.         super.setClipChildren(false);  
    54.     }  
    55.     public HeaderGridView(Context context) {  
    56.         super(context);  
    57.         initHeaderGridView();  
    58.     }  
    59.     public HeaderGridView(Context context, AttributeSet attrs) {  
    60.         super(context, attrs);  
    61.         initHeaderGridView();  
    62.     }  
    63.     public HeaderGridView(Context context, AttributeSet attrs, int defStyle) {  
    64.         super(context, attrs, defStyle);  
    65.         initHeaderGridView();  
    66.     }  
    67.     @Override  
    68.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    69.         super.onMeasure(widthMeasureSpec, heightMeasureSpec);  
    70.         ListAdapter adapter = getAdapter();  
    71.         if (adapter != null && adapter instanceof HeaderViewGridAdapter) {  
    72.             ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumns());  
    73.         }  
    74.     }  
    75.     @Override  
    76.     public void setClipChildren(boolean clipChildren) {  
    77.        // Ignore, since the header rows depend on not being clipped  
    78.     }  
    79.     /** 
    80.      * Add a fixed view to appear at the top of the grid. If addHeaderView is 
    81.      * called more than once, the views will appear in the order they were 
    82.      * added. Views added using this call can take focus if they want. 
    83.      * <p> 
    84.      * NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap 
    85.      * the supplied cursor with one that will also account for header views. 
    86.      * 
    87.      * @param v The view to add. 
    88.      * @param data Data to associate with this view 
    89.      * @param isSelectable whether the item is selectable 
    90.      */  
    91.     public void addHeaderView(View v, Object data, boolean isSelectable) {  
    92.         ListAdapter adapter = getAdapter();  
    93.         if (adapter != null && ! (adapter instanceof HeaderViewGridAdapter)) {  
    94.             throw new IllegalStateException(  
    95.                     "Cannot add header view to grid -- setAdapter has already been called.");  
    96.         }  
    97.         FixedViewInfo info = new FixedViewInfo();  
    98.         FrameLayout fl = new FullWidthFixedViewLayout(getContext());  
    99.         fl.addView(v);  
    100.         info.view = v;  
    101.         info.viewContainer = fl;  
    102.         info.data = data;  
    103.         info.isSelectable = isSelectable;  
    104.         mHeaderViewInfos.add(info);  
    105.         // in the case of re-adding a header view, or adding one later on,  
    106.         // we need to notify the observer  
    107.         if (adapter != null) {  
    108.             ((HeaderViewGridAdapter) adapter).notifyDataSetChanged();  
    109.         }  
    110.     }  
    111.     /** 
    112.      * Add a fixed view to appear at the top of the grid. If addHeaderView is 
    113.      * called more than once, the views will appear in the order they were 
    114.      * added. Views added using this call can take focus if they want. 
    115.      * <p> 
    116.      * NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap 
    117.      * the supplied cursor with one that will also account for header views. 
    118.      * 
    119.      * @param v The view to add. 
    120.      */  
    121.     public void addHeaderView(View v) {  
    122.         addHeaderView(v, null, true);  
    123.     }  
    124.     public int getHeaderViewCount() {  
    125.         return mHeaderViewInfos.size();  
    126.     }  
    127.     /** 
    128.      * Removes a previously-added header view. 
    129.      * 
    130.      * @param v The view to remove 
    131.      * @return true if the view was removed, false if the view was not a header 
    132.      *         view 
    133.      */  
    134.     public boolean removeHeaderView(View v) {  
    135.         if (mHeaderViewInfos.size() > 0) {  
    136.             boolean result = false;  
    137.             ListAdapter adapter = getAdapter();  
    138.             if (adapter != null && ((HeaderViewGridAdapter) adapter).removeHeader(v)) {  
    139.                 result = true;  
    140.             }  
    141.             removeFixedViewInfo(v, mHeaderViewInfos);  
    142.             return result;  
    143.         }  
    144.         return false;  
    145.     }  
    146.     private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) {  
    147.         int len = where.size();  
    148.         for (int i = 0; i < len; ++i) {  
    149.             FixedViewInfo info = where.get(i);  
    150.             if (info.view == v) {  
    151.                 where.remove(i);  
    152.                 break;  
    153.             }  
    154.         }  
    155.     }  
    156.     @Override  
    157.     public void setAdapter(ListAdapter adapter) {  
    158.         if (mHeaderViewInfos.size() > 0) {  
    159.             HeaderViewGridAdapter hadapter = new HeaderViewGridAdapter(mHeaderViewInfos, adapter);  
    160.             int numColumns = getNumColumns();  
    161.             if (numColumns > 1) {  
    162.                 hadapter.setNumColumns(numColumns);  
    163.             }  
    164.             super.setAdapter(hadapter);  
    165.         } else {  
    166.             super.setAdapter(adapter);  
    167.         }  
    168.     }  
    169.     private class FullWidthFixedViewLayout extends FrameLayout {  
    170.         public FullWidthFixedViewLayout(Context context) {  
    171.             super(context);  
    172.         }  
    173.         @Override  
    174.         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    175.             int targetWidth = HeaderGridView.this.getMeasuredWidth()  
    176.                     - HeaderGridView.this.getPaddingLeft()  
    177.                     - HeaderGridView.this.getPaddingRight();  
    178.             widthMeasureSpec = MeasureSpec.makeMeasureSpec(targetWidth,  
    179.                     MeasureSpec.getMode(widthMeasureSpec));  
    180.             super.onMeasure(widthMeasureSpec, heightMeasureSpec);  
    181.         }  
    182.     }  
    183.     /** 
    184.      * ListAdapter used when a HeaderGridView has header views. This ListAdapter 
    185.      * wraps another one and also keeps track of the header views and their 
    186.      * associated data objects. 
    187.      *<p>This is intended as a base class; you will probably not need to 
    188.      * use this class directly in your own code. 
    189.      */  
    190.     private static class HeaderViewGridAdapter implements WrapperListAdapter, Filterable {  
    191.         // This is used to notify the container of updates relating to number of columns  
    192.         // or headers changing, which changes the number of placeholders needed  
    193.         private final DataSetObservable mDataSetObservable = new DataSetObservable();  
    194.         private final ListAdapter mAdapter;  
    195.         private int mNumColumns = 1;  
    196.         // This ArrayList is assumed to NOT be null.  
    197.         ArrayList<FixedViewInfo> mHeaderViewInfos;  
    198.         boolean mAreAllFixedViewsSelectable;  
    199.         private final boolean mIsFilterable;  
    200.         public HeaderViewGridAdapter(ArrayList<FixedViewInfo> headerViewInfos, ListAdapter adapter) {  
    201.             mAdapter = adapter;  
    202.             mIsFilterable = adapter instanceof Filterable;  
    203.             if (headerViewInfos == null) {  
    204.                 throw new IllegalArgumentException("headerViewInfos cannot be null");  
    205.             }  
    206.             mHeaderViewInfos = headerViewInfos;  
    207.             mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos);  
    208.         }  
    209.         public int getHeadersCount() {  
    210.             return mHeaderViewInfos.size();  
    211.         }  
    212.         @Override  
    213.         public boolean isEmpty() {  
    214.             return (mAdapter == null || mAdapter.isEmpty()) && getHeadersCount() == 0;  
    215.         }  
    216.         public void setNumColumns(int numColumns) {  
    217.             if (numColumns < 1) {  
    218.                 throw new IllegalArgumentException("Number of columns must be 1 or more");  
    219.             }  
    220.             if (mNumColumns != numColumns) {  
    221.                 mNumColumns = numColumns;  
    222.                 notifyDataSetChanged();  
    223.             }  
    224.         }  
    225.         private boolean areAllListInfosSelectable(ArrayList<FixedViewInfo> infos) {  
    226.             if (infos != null) {  
    227.                 for (FixedViewInfo info : infos) {  
    228.                     if (!info.isSelectable) {  
    229.                         return false;  
    230.                     }  
    231.                 }  
    232.             }  
    233.             return true;  
    234.         }  
    235.         public boolean removeHeader(View v) {  
    236.             for (int i = 0; i < mHeaderViewInfos.size(); i++) {  
    237.                 FixedViewInfo info = mHeaderViewInfos.get(i);  
    238.                 if (info.view == v) {  
    239.                     mHeaderViewInfos.remove(i);  
    240.                     mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos);  
    241.                     mDataSetObservable.notifyChanged();  
    242.                     return true;  
    243.                 }  
    244.             }  
    245.             return false;  
    246.         }  
    247.         @Override  
    248.         public int getCount() {  
    249.             if (mAdapter != null) {  
    250.                 return getHeadersCount() * mNumColumns + mAdapter.getCount();  
    251.             } else {  
    252.                 return getHeadersCount() * mNumColumns;  
    253.             }  
    254.         }  
    255.         @Override  
    256.         public boolean areAllItemsEnabled() {  
    257.             if (mAdapter != null) {  
    258.                 return mAreAllFixedViewsSelectable && mAdapter.areAllItemsEnabled();  
    259.             } else {  
    260.                 return true;  
    261.             }  
    262.         }  
    263.         @Override  
    264.         public boolean isEnabled(int position) {  
    265.             // Header (negative positions will throw an ArrayIndexOutOfBoundsException)  
    266.             int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;  
    267.             if (position < numHeadersAndPlaceholders) {  
    268.                 return (position % mNumColumns == 0)  
    269.                         && mHeaderViewInfos.get(position / mNumColumns).isSelectable;  
    270.             }  
    271.             // Adapter  
    272.             final int adjPosition = position - numHeadersAndPlaceholders;  
    273.             int adapterCount = 0;  
    274.             if (mAdapter != null) {  
    275.                 adapterCount = mAdapter.getCount();  
    276.                 if (adjPosition < adapterCount) {  
    277.                     return mAdapter.isEnabled(adjPosition);  
    278.                 }  
    279.             }  
    280.             throw new ArrayIndexOutOfBoundsException(position);  
    281.         }  
    282.         @Override  
    283.         public Object getItem(int position) {  
    284.             // Header (negative positions will throw an ArrayIndexOutOfBoundsException)  
    285.             int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;  
    286.             if (position < numHeadersAndPlaceholders) {  
    287.                 if (position % mNumColumns == 0) {  
    288.                     return mHeaderViewInfos.get(position / mNumColumns).data;  
    289.                 }  
    290.                 return null;  
    291.             }  
    292.             // Adapter  
    293.             final int adjPosition = position - numHeadersAndPlaceholders;  
    294.             int adapterCount = 0;  
    295.             if (mAdapter != null) {  
    296.                 adapterCount = mAdapter.getCount();  
    297.                 if (adjPosition < adapterCount) {  
    298.                     return mAdapter.getItem(adjPosition);  
    299.                 }  
    300.             }  
    301.             throw new ArrayIndexOutOfBoundsException(position);  
    302.         }  
    303.         @Override  
    304.         public long getItemId(int position) {  
    305.             int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;  
    306.             if (mAdapter != null && position >= numHeadersAndPlaceholders) {  
    307.                 int adjPosition = position - numHeadersAndPlaceholders;  
    308.                 int adapterCount = mAdapter.getCount();  
    309.                 if (adjPosition < adapterCount) {  
    310.                     return mAdapter.getItemId(adjPosition);  
    311.                 }  
    312.             }  
    313.             return -1;  
    314.         }  
    315.         @Override  
    316.         public boolean hasStableIds() {  
    317.             if (mAdapter != null) {  
    318.                 return mAdapter.hasStableIds();  
    319.             }  
    320.             return false;  
    321.         }  
    322.         @Override  
    323.         public View getView(int position, View convertView, ViewGroup parent) {  
    324.             // Header (negative positions will throw an ArrayIndexOutOfBoundsException)  
    325.             int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns ;  
    326.             if (position < numHeadersAndPlaceholders) {  
    327.                 View headerViewContainer = mHeaderViewInfos  
    328.                         .get(position / mNumColumns).viewContainer;  
    329.                 if (position % mNumColumns == 0) {  
    330.                     return headerViewContainer;  
    331.                 } else {  
    332.                     if (convertView == null) {  
    333.                         convertView = new View(parent.getContext());  
    334.                     }  
    335.                     // We need to do this because GridView uses the height of the last item  
    336.                     // in a row to determine the height for the entire row.  
    337.                     convertView.setVisibility(View.INVISIBLE);  
    338.                     convertView.setMinimumHeight(headerViewContainer.getHeight());  
    339.                     return convertView;  
    340.                 }  
    341.             }  
    342.             // Adapter  
    343.             final int adjPosition = position - numHeadersAndPlaceholders;  
    344.             int adapterCount = 0;  
    345.             if (mAdapter != null) {  
    346.                 adapterCount = mAdapter.getCount();  
    347.                 if (adjPosition < adapterCount) {  
    348.                     return mAdapter.getView(adjPosition, convertView, parent);  
    349.                 }  
    350.             }  
    351.             throw new ArrayIndexOutOfBoundsException(position);  
    352.         }  
    353.         @Override  
    354.         public int getItemViewType(int position) {  
    355.             int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;  
    356.             if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {  
    357.                 // Placeholders get the last view type number  
    358.                 return mAdapter != null ? mAdapter.getViewTypeCount() : 1;  
    359.             }  
    360.             if (mAdapter != null && position >= numHeadersAndPlaceholders) {  
    361.                 int adjPosition = position - numHeadersAndPlaceholders;  
    362.                 int adapterCount = mAdapter.getCount();  
    363.                 if (adjPosition < adapterCount) {  
    364.                     return mAdapter.getItemViewType(adjPosition);  
    365.                 }  
    366.             }  
    367.             return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;  
    368.         }  
    369.         @Override  
    370.         public int getViewTypeCount() {  
    371.             if (mAdapter != null) {  
    372.                 return mAdapter.getViewTypeCount() + 1;  
    373.             }  
    374.             return 2;  
    375.         }  
    376.         @Override  
    377.         public void registerDataSetObserver(DataSetObserver observer) {  
    378.             mDataSetObservable.registerObserver(observer);  
    379.             if (mAdapter != null) {  
    380.                 mAdapter.registerDataSetObserver(observer);  
    381.             }  
    382.         }  
    383.         @Override  
    384.         public void unregisterDataSetObserver(DataSetObserver observer) {  
    385.             mDataSetObservable.unregisterObserver(observer);  
    386.             if (mAdapter != null) {  
    387.                 mAdapter.unregisterDataSetObserver(observer);  
    388.             }  
    389.         }  
    390.         @Override  
    391.         public Filter getFilter() {  
    392.             if (mIsFilterable) {  
    393.                 return ((Filterable) mAdapter).getFilter();  
    394.             }  
    395.             return null;  
    396.         }  
    397.         @Override  
    398.         public ListAdapter getWrappedAdapter() {  
    399.             return mAdapter;  
    400.         }  
    401.         public void notifyDataSetChanged() {  
    402.             mDataSetObservable.notifyChanged();  
    403.         }  
    404.     }  
    405. }  

    代码地址:https://android.googlesource.com/platform/packages/apps/Gallery2/+/idea133/src/com/android/photos/

  • 相关阅读:
    python生成xml文件
    gcc基本用法
    Java删除文件或目录及目录下所有文件
    QTimer在QThread环境中失效的问题
    fopen打开文件失败的问题
    利用枚举,简化多个标志位统计
    QTableView表格自动拉伸
    django1.11 启动错误:Generator expression must be parenthesized
    css选择器
    property使用
  • 原文地址:https://www.cnblogs.com/cheneasternsun/p/6080683.html
Copyright © 2020-2023  润新知