(自定义ListView控件)在ExpandableListAdapter中嵌套ListView
2015-10-07 21:44
411 查看
在ExpandableListAdapter中嵌套ListView
如果只是单纯的ListView
经试验,在模拟器中只显示两项,在手机中显示1项
若改成自定义的ListView控件,则正常显示
Activity外面写MyListView的类,如下图
至于为什么要单独成类我不清楚,但是试验过,如果把Class MyListView卸载Activity里面,并不会起作用,仍然只显示两项,但写在外面则显示正常
这是今天下午学长告诉我要这样写的,具体原因以后补上
MyListView.java代码
布局文件中MyListView,格式<包名.MyListView>
Activity.java中引用MyListView的代码
来个对比图(图一为改前效果,图二为改后效果)
如果只是单纯的ListView
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { // TODO Auto-generated method stub LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout view = (LinearLayout) layoutInflater.inflate(R.layout.dialog_item2, null); view.setPadding(0, 0, 0, 15); TextView tvCon = (TextView)view.findViewById(R.id.con); tvCon.setText(conte[childPosition]); tvCon.setPadding(0, 10, 0, 10); tvCon.setTextSize(18); MyAdapter2 m2=new MyAdapter2(teamNum*4+groupPosition,MainActivity.this);//teamNum*4+groupPosition=which国家 MyListView conlv=(MyListView)view.findViewById(R.id.conlv); conlv.setAdapter(m2); return view; }
经试验,在模拟器中只显示两项,在手机中显示1项
若改成自定义的ListView控件,则正常显示
Activity外面写MyListView的类,如下图
至于为什么要单独成类我不清楚,但是试验过,如果把Class MyListView卸载Activity里面,并不会起作用,仍然只显示两项,但写在外面则显示正常
这是今天下午学长告诉我要这样写的,具体原因以后补上
MyListView.java代码
public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(android.content.Context context, android.util.AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
布局文件中MyListView,格式<包名.MyListView>
<com.example.euro2012_0930.MyListView android:id="@+id/conlv" android:layout_width="match_parent" android:layout_height="match_parent"> </com.example.euro2012_0930.MyListView>
Activity.java中引用MyListView的代码
MyListView conlv=(MyListView)view.findViewById(R.id.conlv);
来个对比图(图一为改前效果,图二为改后效果)
相关文章推荐
- C# 将PPT文件转换成PDF文件
- 数据库的设计
- 认为手机成掌机最大阻碍 索尼服软为哪般
- 二层交换机管理问题、管理VLAN的概念详解
- MFC 树形控件与列表控件
- EasyUI的中Tree
- HDU 1212 Big Number(大数取模)
- 数据库的建立
- 匿名函数
- HDU 3966 Aragorn's Story(树剖-点)
- Git 配置
- [经典进程同步问题]哲学家思考
- Java基础知识强化之网络编程笔记05:UDP之多线程实现聊天室案例
- 双目视觉学习总结(3)——立体匹配
- C#学习之多线程开发技术(十二)
- 13种排序算法详解(相当清楚,还附有flash动画)
- windows程序内部运行原理
- POJ 1200 字符串哈希
- 如何远程格式化迅雷宝硬盘
- 数据结构之自建算法库——广义表