public class OrderingExpandAdapter extends BaseExpandableListAdapter { public OrderingExpandAdapter(Context ctx, ArrayList<String> groupTitle, List<List> list, Handler handler) { mContext = ctx; mSize = BitmapUtils.getSize(ctx, 60); mInflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mHandler = handler; initImageLoader(); setData(groupTitle, list); } private void setData(ArrayList<String> groupTitle, List<List> list) { if (groupTitle == null) { mGroupList = new ArrayList<String>(); } else { mGroupList = groupTitle; } if (list == null) { mData = new ArrayList<List>(); } else { mData = list; } } public void refreshData(ArrayList<String> groupTitle, List<List> list) { setData(groupTitle, list); notifyDataSetChanged(); } public void refreshData(List<List> list) { setData(mGroupList, list); notifyDataSetChanged(); } public void refreshData() { notifyDataSetChanged(); } private void initImageLoader() { mImageLoader = ImageLoader.getInstance(); options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_stub) .showImageForEmptyUri(R.drawable.ic_empty) .showImageOnFail(R.drawable.ic_error).cacheInMemory(true) .cacheOnDisc(true).considerExifParams(true) .displayer(new SimpleBitmapDisplayer()).build(); } public void setData(List<List> list) { mData = list; } @Override public int getGroupCount() { // TODO Auto-generated method stub return mData.size(); } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return mData.get(groupPosition).size(); } @Override public List getGroup(int groupPosition) { // TODO Auto-generated method stub return mData.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return mData.get(groupPosition).get(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 false; } //groupview中需要布局复用 @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { // TODO Auto-generated method stub GroupViewHolder holder = null; if (convertView == null) { holder = new GroupViewHolder(); convertView = mInflater.inflate(R.layout.auto_ordering_group_item, null); // } holder.mGroupName = (TextView) convertView .findViewById(R.id.tvgroupname); holder.mImageView = (ImageView) convertView .findViewById(R.id.ivorderarrow); convertView.setTag(R.layout.auto_ordering_group_item, holder); } else { holder = (GroupViewHolder) convertView .getTag(R.layout.auto_ordering_group_item); } if (mGroupList != null) { holder.mGroupName.setText(mGroupList.get(groupPosition)); } if (isExpanded) { holder.mImageView .setBackgroundResource(R.drawable.order_arrow_down); } else { holder.mImageView .setBackgroundResource(R.drawable.order_arrow_right); } return convertView; } //childview中需要布局复用 @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { ChildViewHolder holder = null; //这里判断 不仅要判断convertView为空还要判断 getTag方面获得布局复用为空 if (convertView == null || null == (ChildViewHolder) convertView.getTag(R.id.idkey0 + (groupPosition+1)*1000+childPosition)) { holder = new ChildViewHolder(); convertView = mInflater.inflate(R.layout.auto_ordering_child_item, null); // } initViewHolder(); // setTag(key,value);键值对模式 使用 //key 要注意 必须再res/value/ids 中声明定义 convertView.setTag(R.id.idkey0 + (groupPosition+1)*1000+childPosition, holder); } else { holder = (ChildViewHolder) convertView.getTag(R.id.idkey0 + (groupPosition+1)*1000+childPosition); } initViewDataHolder(); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub /* 很重要:实现ChildView点击事件,必须返回true */ return false; } private class GroupViewHolder { ImageView mImageView; TextView mGroupName; } private class ChildViewHolder { // iv/ivmoreshoptitle/rlsurplustime/tvsurplustime/tvtitle/tvnowprice/tvoriginalprice // tvpeople/btadd0/lladd1/btminus/btmid/btminus ImageView ivBack; ImageView ivMS; RelativeLayout rlSurplusTime; TextView tvSurplusTime; TextView tvTitle; TextView tvNowPrice; TextView tvOriginalPrice; RelativeLayout rlPeople; TextView tvPeople; Button btAdd0; LinearLayout llAdd1; Button btMinus; Button btMid; Button btAdd; } }
ExpandableList 这里需要3个布局:
1、在activity中的listview
2、child_item
3、group_item
include 外面要包个linearlayout
android:layout_weight="1"
可以控制scrollview的挤压下层view,导致不显示
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。