91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android中ExpandableListView使用示例詳解

發布時間:2020-09-07 06:54:25 來源:腳本之家 閱讀:202 作者:JustingWang_1 欄目:移動開發

本文實例為大家分享了ExpandableListView使用示例,供大家參考,具體內容如下

MainActivity:

public class Expandable_test extends Activity {
  private ExpandableListView listView;
  private Map<String, List<String>> dataset = new HashMap<>();
  private String[] parentList = new String[]{"第一個菜單", "第二個菜單"};

  private ExpandableListViewAdpter adpter;
  private Context mContext = this;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_expandable_test);
    listView=(ExpandableListView)findViewById(R.id.expandableListViewtext);
    adpter=new ExpandableListViewAdpter(this,parentList);
    listView.setAdapter(adpter);
  }

}

MainActivity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.fae.mobile.testActivity.Expandable_test">
<ExpandableListView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/expandableListViewtext">

</ExpandableListView>
</LinearLayout>

ExpandableListViewAdpter:

public class ExpandableListViewAdpter extends BaseExpandableListAdapter {
  private Context mContext;
  private Map<String, List<String>> dataset = new HashMap<>();
  private String[] parentList = new String[]{"第一個菜單", "第二個菜單"};
  private String[][] chdrenList=new String[][]
      {{"菜單1","菜單1","菜單1","菜單1","菜單1","菜單1"},{"菜單2","菜單2","菜單2","菜單2","菜單2"}};

  public ExpandableListViewAdpter(Context context, String[] parentList){
    this.mContext=context;
    this.dataset=dataset;
    this.parentList=parentList;
  }

  @Override
  public int getGroupCount() {
    return parentList.length;
  }

  @Override
  public int getChildrenCount(int groupPosition) {
    return chdrenList[groupPosition].length;
  }

  @Override
  public Object getGroup(int groupPosition) {
    return parentList[groupPosition];
  }

  @Override
  public Object getChild(int groupPosition, int childPosition) {
    return chdrenList[groupPosition][childPosition];
  }

  @Override
  public long getGroupId(int groupPosition) {
    return groupPosition;
  }

  @Override
  public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
  }

  @Override
  public boolean hasStableIds() {
    return true;
  }

  @Override
  public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    GroupViewHolder holder=null;
    if(convertView==null){
      convertView = LayoutInflater.from(mContext).inflate(R.layout.itemlayoutexpandable, null);
      holder=new GroupViewHolder();
      holder.text=(TextView)convertView.findViewById(R.id.item_text);
      convertView.setTag(holder);
    }
    else {
      holder=(GroupViewHolder)convertView.getTag();
    }
    holder.text.setText(parentList[groupPosition]);
    return convertView;
  }

  @Override
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ChildViewHolder holder=null;
      if(convertView==null){
        convertView = LayoutInflater.from(mContext).inflate(R.layout.itemlayoutexpandable, null);
        holder=new ChildViewHolder();
        holder.text=(TextView)convertView.findViewById(R.id.item_text);
        convertView.setTag(holder);
    }
    else {
        holder=(ChildViewHolder)convertView.getTag();
      }
      holder.text.setText(chdrenList[groupPosition][childPosition]);
    return convertView;
  }

  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
  }
  class GroupViewHolder {
    TextView text;
  }

  class ChildViewHolder {
    TextView text;
  }
}

Item.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<TextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="bottom"
  android:id="@+id/item_text"/>
</LinearLayout>

Android中ExpandableListView使用示例詳解

Android中ExpandableListView使用示例詳解

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

绍兴县| 山丹县| 无锡市| 夏津县| 广灵县| 顺平县| 盐池县| 绵阳市| 梅河口市| 遵化市| 嘉鱼县| 鄂尔多斯市| 茂名市| 友谊县| 霍城县| 大洼县| 临邑县| 石泉县| 屏东县| 二连浩特市| 茶陵县| 那曲县| 长阳| 元江| 康乐县| 福泉市| 九江县| 余姚市| 额济纳旗| 巴楚县| 枣庄市| 朔州市| 托里县| 长泰县| 高阳县| 开平市| 苗栗县| 桂阳县| 临夏市| 城市| 清丰县|