最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中ExpandableListView的用法實(shí)例

 更新時間:2014年10月14日 09:32:44   投稿:shichen2014  
這篇文章主要介紹了Android中ExpandableListView的用法,以實(shí)例形式展示了Android中的下拉list控件的用法,需要的朋友可以參考下

本文實(shí)例講述了Android中ExpandableListView的用法,ExpandableListView是android中可以實(shí)現(xiàn)下拉list的一個控件,具體的實(shí)現(xiàn)方法如下:

首先:在layout的xml文件中定義一個ExpandableListView

復(fù)制代碼 代碼如下:
<LinearLayout  
    android:id="@+id/linearLayout" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    androidrientation="vertical" 
    > 
     
    <ExpandableListView 
    android:id="@+id/expandableListView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
        /> 
</LinearLayout>

定義兩個List,用來存放控件中Group/Child中的String

復(fù)制代碼 代碼如下:
private List<String> groupArray; 
private List<List<String>> childArray;

對這兩個List進(jìn)行初始化,并插入一些數(shù)據(jù)

復(fù)制代碼 代碼如下:
groupArray = new ArrayList<String>(); 
childArray = new ArrayList<List<String>>(); 
 
groupArray.add("第一行"); 
groupArray.add("第二行"); 
 
List<String> tempArray = new ArrayList<String>(); 
tempArray.add("第一條"); 
tempArray.add("第二條"); 
tempArray.add("第三條"); 
 
for(int index = 0; index <groupArray.size(); ++index) 

    childArray.add(tempArray); 
}

定義ExpandableListView的Adapter

復(fù)制代碼 代碼如下:
//ExpandableListView的Adapter 
public class ExpandableAdapter extends BaseExpandableListAdapter 

    Activity activity; 
     
    public ExpandableAdapter(Activity a) 
    { 
        activity = a; 
    } 
    public Object getChild(int groupPosition, int childPosition) 
    { 
        return childArray.get(groupPosition).get(childPosition); 
    } 
    public long getChildId(int groupPosition, int childPosition) 
    { 
        return childPosition; 
    } 
    public int getChildrenCount(int groupPosition) 
    { 
        return childArray.get(groupPosition).size(); 
    } 
    public View getChildView(int groupPosition, int childPosition, 
            boolean isLastChild, View convertView, ViewGroup parent) 
    { 
        String string = childArray.get(groupPosition).get(childPosition); 
        return getGenericView(string); 
    } 
    // group method stub 
    public Object getGroup(int groupPosition) 
    { 
        return groupArray.get(groupPosition); 
    } 
    public int getGroupCount() 
    { 
        return groupArray.size(); 
    } 
    public long getGroupId(int groupPosition) 
    { 
        return groupPosition; 
    } 
    public View getGroupView(int groupPosition, boolean isExpanded, 
            View convertView, ViewGroup parent) 
    { 
        String string = groupArray.get(groupPosition); 
        return getGenericView(string); 
    } 
    // View stub to create Group/Children 's View 
    public TextView getGenericView(String string) 
    { 
        // Layout parameters for the ExpandableListView 
        AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams( 
                ViewGroup.LayoutParams.FILL_PARENT, 64); 
        TextView text = new TextView(activity); 
        text.setLayoutParams(layoutParams); 
        // Center the text vertically 
        text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
        // Set the text starting position 
        text.setPadding(36, 0, 0, 0); 
        text.setText(string); 
        return text; 
    } 
    public boolean hasStableIds() 
    { 
        return false; 
    } 
    public boolean isChildSelectable(int groupPosition, int childPosition) 
    { 
        return true; 
    } 
}

最后,給定義好的ExpandableListView添加上Adapter

復(fù)制代碼 代碼如下:
ExpandableListView expandableListView = (ExpandableListView)findViewById(R.id.expandableListView); 
expandableListView.setAdapter(new ExpandableAdapter(Main.this));

希望本文所述對大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android 高仿微信語音聊天頁面高斯模糊(毛玻璃效果)

    Android 高仿微信語音聊天頁面高斯模糊(毛玻璃效果)

    大家在使用微信聊天的時候有沒有注意到微信語言聊天用的是高斯模糊效果,基于代碼是如何實(shí)現(xiàn)的呢?下面小編給大家?guī)砹薃ndroid 高仿微信語音聊天頁面高斯模糊(毛玻璃效果),感興趣的朋友一起看下吧
    2016-08-08
  • Android實(shí)現(xiàn)鬧鐘小程序

    Android實(shí)現(xiàn)鬧鐘小程序

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)鬧鐘小程序,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • android studio如何通過 jni 調(diào)用第三方非標(biāo)準(zhǔn) so庫

    android studio如何通過 jni 調(diào)用第三方非標(biāo)準(zhǔn) so庫

    這篇文章主要介紹了android studio如何通過 jni 調(diào)用第三方非標(biāo)準(zhǔn) so庫,調(diào)用第三方的so方法,但這個so內(nèi)的方法不是標(biāo)準(zhǔn)的jni方法,這就需要我們自己寫jni然后鏈接到第三方so庫,通過jni調(diào)用so庫中的方法,需要的朋友可以參考下
    2025-04-04
  • Android編程中context及全局變量實(shí)例詳解

    Android編程中context及全局變量實(shí)例詳解

    這篇文章主要介紹了Android編程中context及全局變量的用法,結(jié)合實(shí)例形式較為詳細(xì)的分析講述了context及全局變量的使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2015-12-12
  • Android Studio快捷鍵生成TAG、Log.x日志輸出介紹

    Android Studio快捷鍵生成TAG、Log.x日志輸出介紹

    這篇文章主要介紹了Android Studio快捷鍵生成TAG、Log.x日志輸出介紹,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • android Listview模擬聊天界面

    android Listview模擬聊天界面

    這篇文章主要為大家詳細(xì)介紹了android Listview模擬聊天界面的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • 從源碼編譯Android系統(tǒng)的Java類庫和JNI動態(tài)庫的方法

    從源碼編譯Android系統(tǒng)的Java類庫和JNI動態(tài)庫的方法

    這篇文章主要介紹了從源碼編譯Android系統(tǒng)的Java類庫和JNI動態(tài)庫的方法,例子基于Linux系統(tǒng)環(huán)境下來講,需要的朋友可以參考下
    2016-02-02
  • Android自定義View實(shí)現(xiàn)豎直跑馬燈效果案例解析

    Android自定義View實(shí)現(xiàn)豎直跑馬燈效果案例解析

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)豎直跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android?MPChart自定義睡眠泳道圖教程示例

    Android?MPChart自定義睡眠泳道圖教程示例

    這篇文章主要為大家介紹了Android?MPChart自定義睡眠泳道圖教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android狀態(tài)欄的適配匯總

    Android狀態(tài)欄的適配匯總

    這篇文章主要給大家介紹了關(guān)于Android狀態(tài)欄適配的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05

最新評論

常州市| 清新县| 龙岩市| 西宁市| 沁源县| 南澳县| 崇仁县| 吴堡县| 陆良县| 达孜县| 灵丘县| 安岳县| 东兴市| 比如县| 玉林市| 边坝县| 九龙城区| 巴林右旗| 金堂县| 张家口市| 聊城市| 时尚| 浦东新区| 黄冈市| 甘孜县| 岳西县| 蓬莱市| 万全县| 克拉玛依市| 拉孜县| 云和县| 镇原县| 平阳县| 崇州市| 香格里拉县| 高阳县| 香河县| 泰来县| 锡林浩特市| 新兴县| 泰顺县|