activity_main.xml
10年积累的成都网站建设、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先制作网站后付款的网站建设流程,更有辽宁免费网站建设让你可以放心的选择与我们合作。<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.expandablelistview.MainActivity" > <ExpandableListView android:id="@+id/ExpandableListView1_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:groupIndicator="@null" > </ExpandableListView> </RelativeLayout> <!-- android:groupIndicator="@null"去掉自带的箭头图标 -->
group_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/p_w_picpathViewgroup_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textViewgroup_1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
child_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/p_w_picpathViewchild_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:padding="10dp" /> <TextView android:id="@+id/textViewchild_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="sdfds" android:padding="10dp" /> </LinearLayout>
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; } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前文章:android的ExpandableListView-创新互联
文章源于:https://www.cdcxhl.com/article16/espdg.html
成都网站建设公司_创新互联,为您提供手机网站建设、做网站、网站策划、品牌网站设计、ChatGPT、定制网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联