(自定义ListView控件)在ExpandableListAdapter中嵌套ListView

在ExpandableListAdapter中嵌套ListView


如果只是单纯的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);

来个对比图(图一为改前效果,图二为改后效果)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值