您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。