android的ExpandableListView
activity_main.xml
永德ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
group_item.xml
child_item.xml
MainActivity
package com.example.expandablelistview; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends Activity { private ExpandableListView expandableListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); expandableListView=(ExpandableListView) findViewById(R.id.ExpandableListView1_1); expandableListView.setAdapter(new MyExpandableListAdapter()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } class MyExpandableListAdapter extends BaseExpandableListAdapter{ private String[] skills = new String[]{ "WORD", "EXCEL", "EMAIL", "PPT" }; private String[][] groups = new String[][]{ {"文档编辑", "文档排版", "文档处理", "文档打印"}, {"表格编辑", "表格排版", "表格处理", "表格打印"}, {"收发邮件", "管理邮箱", "登录登出", "注册绑定"}, {"演示编辑", "演示排版", "演示处理", "演示打印"}, }; @Override public int getGroupCount() { // TODO Auto-generated method stub return skills.length; } //二级列表的数量 @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return groups[groupPosition].length; } //返回每一组的对象 @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return skills[groupPosition]; } //返回每组中的列表项 @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return groups[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return true; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null){ convertView=getLayoutInflater().inflate(R.layout.group_item, null); } ImageView p_w_picpathView=(ImageView) convertView.findViewById(R.id.p_w_picpathViewgroup_1); TextView textView=(TextView) convertView.findViewById(R.id.textViewgroup_1); p_w_picpathView.setImageResource(R.drawable.ic_launcher); textView.setText(skills[groupPosition]); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null){ convertView=getLayoutInflater().inflate(R.layout.child_item, null); ImageView p_w_picpathView=(ImageView) convertView.findViewById(R.id.p_w_picpathViewchild_1); TextView textView=(TextView) convertView.findViewById(R.id.textViewchild_1); p_w_picpathView.setImageResource(R.drawable.ic_launcher); textView.setText(groups[groupPosition][childPosition]); } return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } } }
本文标题:android的ExpandableListView
文章出自:http://pwwzsj.com/article/jhpsch.html