您的位置:首页 > 其它

二级列表ExpandableListView

2015-08-11 16:52 309 查看
有时候ListView不能满足项目中的所有需求,有时候需要多组Listview,就像QQ中的,我的好友那样点击一下展开,再点击一下又收缩回去,就是用到了ExpandableListView。

ExpandableListView的关键在于设置它的adapter ,它的adapter需要继承BaseExpandableListAdapter。

 

     下面是一个demo:

    


//布局

ac_my_account.xml:

   <?xml version="1.0" encoding="utf-8"?>

  <LinearLayout 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:orientation="vertical"

    tools:context=".account.activity.AccountSettingActivity" >

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical" >

            <RelativeLayout

                android:id="@+id/rl_my_account_title"

                android:layout_width="fill_parent"

                android:layout_height="50dip"

                android:layout_gravity="center_vertical"

                android:background="@drawable/ok"

                android:paddingRight="10dip" >

                <FrameLayout

                    android:id="@+id/fl_my_account_goback"

                    android:layout_width="80dp"

                    android:layout_height="50dp"

                    android:layout_alignParentLeft="true"

                    android:layout_centerVertical="true" >

                    <ImageView

                        android:id="@+id/iv_my_account_goback"

                        android:layout_width="50dip"

                        android:layout_height="25dip"

                        android:layout_gravity="center_vertical"

                        android:clickable="true"

                        android:src="@drawable/button_back_bg" />

                </FrameLayout>

                <TextView

                    android:id="@+id/tv_account_content"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_centerInParent="true"

                    android:background="@color/transparent"

                    android:clickable="true"

                    android:text="我的账户"

                    android:textColor="@color/white"

                    android:textSize="16sp" />

            </RelativeLayout>

            <LinearLayout

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="20dp"

                android:orientation="horizontal" >

                <TextView

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:text="我的账户 :"

                    android:textSize="16sp" />

                <TextView

                    android:id="@+id/tv_my_account_phone"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_marginLeft="5dp"

                    android:text="152152251151"

                    android:textSize="16sp" />

            </LinearLayout>

            <View

                android:layout_width="match_parent"

                android:layout_height="0.1dp"

                android:background="@color/line" />

            <LinearLayout

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:layout_margin="15dp"

                android:orientation="horizontal" >

                <TextView

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_marginLeft="5dp"

                    android:text="账号类型  :"

                    android:textSize="16sp" />

                <TextView

                    android:id="@+id/tv_my_account_type"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_marginLeft="5dp"

                    android:text="个人"

                    android:textSize="16sp" />

            </LinearLayout>

            <View

                android:layout_width="match_parent"

                android:layout_height="0.1dp"

                android:background="@color/line" />

     <ScrollView

        android:id="@+id/sview"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:fadingEdge="none"

        android:scrollbars="none" >

            <LinearLayout

                android:id="@+id/ll_buy_history"

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:orientation="vertical"

                android:visibility="visible"

                >

                <LinearLayout

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:layout_margin="13dp"

                    android:orientation="horizontal" >

                    <TextView

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:layout_marginLeft="10dp"

                        android:text="我的权益 :"

                        android:textSize="16sp" />

                </LinearLayout>

                <View

                    android:layou
4000
t_width="match_parent"

                    android:layout_height="0.1dp"

                    android:background="@color/line" />

                <LinearLayout

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:orientation="vertical" >

                    <com.gldjc.gcsupplier.ZListView.NoScrollListView2

                        android:id="@+id/lv_my_accout_my_rights"

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:layout_marginLeft="20dp"

                        android:layout_marginRight="15dp"

                        android:scrollbars="none" />

                </LinearLayout>

                <View

                    android:layout_width="match_parent"

                    android:layout_height="0.1dp"

                    android:background="@color/line" />

                <RelativeLayout

                    android:id="@+id/rl_account_show_more"

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:gravity="center"

                    android:visibility="gone"

                    >

                    <TextView

                        android:id="@+id/tv_account_show_more"

                        android:layout_width="wrap_content"

                        android:layout_height="wrap_content"

                        android:drawablePadding="5dp"

                        android:drawableRight="@drawable/project_detail_up"

                        android:gravity="center"

                        android:padding="6dp"

                        android:text="全部5条"

                        android:textColor="@color/hintColor"

                        android:textSize="16sp" />

                </RelativeLayout>

                

                <LinearLayout

        android:id="@+id/ll_no_history"

        android:layout_width="match_parent"

        android:layout_height="fill_parent"

        android:background="@color/item_selected"

        android:gravity="center"

        android:orientation="vertical"

        android:visibility="gone"

        >

        <TextView

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:gravity="center"

            android:text="您还没有购买记录!"

            android:textSize="16sp" />

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginBottom="50dp"

            android:layout_marginTop="10dp"

            android:gravity="center"

            android:orientation="horizontal" >

            <TextView

                android:id="@+id/tv_buy_now"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginRight="5dp"

                android:background="@drawable/tv_my_account_bg"

                android:gravity="center"

                android:padding="3dp"

                android:text="立即购买"

                android:textColor="@color/bind_phone_title_color"

                android:textSize="16sp" />

            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="获取海量商机!"

                android:textSize="16sp" />

        </LinearLayout>

    </LinearLayout>

                <View

                    android:layout_width="match_parent"

                    android:layout_height="0.1dp"

                    android:background="@color/line" />

                <LinearLayout

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:layout_margin="13dp"

                    android:orientation="horizontal" >

                    <TextView

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:layout_marginLeft="10dp"

                        android:text="未支付订单 :"

                        android:textSize="16sp" />

                </LinearLayout>

                <View

                    android:layout_width="match_parent"

                    android:layout_height="0.1dp"

                    android:background="@color/line" />

                <LinearLayout

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:orientation="vertical" >

                  <!--  <ExpandableListView

                        android:id="@+id/lv_my_accout_unpaid_orders"

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:layout_marginLeft="20dp"

                        android:layout_marginRight="15dp"

                        android:scrollbars="none" >

                        </ExpandableListView> -->

                        

                    <com.gldjc.gcsupplier.ZListView.NoScrollListView

                        android:id="@+id/lv_my_accout_unpaid_orders"

                        android:layout_width="fill_parent"

                        android:layout_height="wrap_content"

                        android:groupIndicator="@null"

                        android:scrollingCache="false" >

                     </com.gldjc.gcsupplier.ZListView.NoScrollListView>

                </LinearLayout>

            </LinearLayout>

            </ScrollView>

        </LinearLayout>

</LinearLayout>

//继承ExpandableListView,并设置高度

NoScrollListView:

package com.gldjc.gcsupplier.ZListView;

import android.annotation.SuppressLint;

import android.content.Context;

import android.content.SharedPreferences;

import android.preference.PreferenceManager;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.view.View;

import android.view.ViewTreeObserver.OnGlobalLayoutListener;

import android.view.animation.DecelerateInterpolator;

import android.widget.AbsListView;

import android.widget.AbsListView.OnScrollListener;

import android.widget.ExpandableListView;

import android.widget.ListAdapter;

import android.widget.ListView;

import android.widget.RelativeLayout;

import android.widget.Scroller;

import android.widget.TextView;

public class NoScrollListView extends ExpandableListView {

    public NoScrollListView(Context context) {

        super(context);

    }

    public NoScrollListView(Context context, AttributeSet attrs) {

        super(context, attrs);

    }

    public NoScrollListView(Context context, AttributeSet attrs, int defStyle) {

        super(context, attrs, defStyle);

    }

    @Override

    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);

        super.onMeasure(widthMeasureSpec, expandSpec);

    }

}

//主Activity

MyAccountActivity.java

package com.gldjc.gcsupplier.account.activity;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

import android.content.Intent;

import android.content.res.Resources;

import android.graphics.drawable.Drawable;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewGroup.LayoutParams;

import android.widget.ExpandableListView;

import android.widget.FrameLayout;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.ListAdapter;

import android.widget.ListView;

import android.widget.RelativeLayout;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.ExpandableListView.OnChildClickListener;

import android.widget.ExpandableListView.OnGroupExpandListener;

import com.gldjc.gcsupplier.MyApplication;

import com.gldjc.gcsupplier.R;

import com.gldjc.gcsupplier.ZListView.NoScrollListView;

import com.gldjc.gcsupplier.ZListView.NoScrollListView2;

import com.gldjc.gcsupplier.activitys.BuyActivity;

import com.gldjc.gcsupplier.activitys.HomeActivity;

import com.gldjc.gcsupplier.activitys.WebViewCopyActivity;

import com.gldjc.gcsupplier.adapter.MyAccountMyRightsAdapter;

import com.gldjc.gcsupplier.adapter.MyAccountUnpaidOrdersAdapter;

import com.gldjc.gcsupplier.base.BaseActivity;

import com.gldjc.gcsupplier.beans.AccessAreaAndPriceBean;

import com.gldjc.gcsupplier.beans.AccessAreaAndPriceListBean;

import com.gldjc.gcsupplier.beans.ChildBean;

import com.gldjc.gcsupplier.beans.GainOrderBean;

import com.gldjc.gcsupplier.beans.GainOrderListBean;

import com.gldjc.gcsupplier.beans.JsonResult;

import com.gldjc.gcsupplier.beans.OrderFromBean;

import com.gldjc.gcsupplier.beans.PrantBean;

import com.gldjc.gcsupplier.beans.RightsAndInterestsBean;

import com.gldjc.gcsupplier.beans.RightsAndInterestsListBean;

import com.gldjc.gcsupplier.beans.RightsAndInterestsReviceBean;

import com.gldjc.gcsupplier.beans.UriBean;

import com.gldjc.gcsupplier.interfaces.OnCommonPostSuccessListener;

import com.gldjc.gcsupplier.net.BaseCommonAsyncTask;

import com.gldjc.gcsupplier.util.BaseShareference;

public class MyAccountActivity extends BaseActivity {

    private FrameLayout flMyAccountGoBack;// 返回

    private ImageView ivMyAccountGoBack;// 返回

    private TextView tvMyAccountPhone;// 我的账户

    private TextView tvMyAccountType;// 账号类型

    private NoScrollListView2 MyAccoutMyRights;// 我的权益

    private RelativeLayout rlAccountShowMore;// 展开/隐藏

    private TextView tvAccountShowMore;// 展开/隐藏

    private NoScrollListView myAccoutUnpaidOrders;// 未支付订单

    private MyAccountMyRightsAdapter madapter;// 我的权益adapter

    private MyAccountUnpaidOrdersAdapter mUnPaidAdapter;// 未支付订单

    private LinearLayout ll_no_history;// 没有购买历史

    private LinearLayout ll_buy_history;// 有购买历史

    private TextView tv_buy_now;// 立即购买

    private TextView tv_account_show_more;// 展开更多

    private boolean isShowMore = false;// 是否展开

    private RightsAndInterestsBean rightsAndInterestsBean;

    private RightsAndInterestsListBean rightsAndInterestsListBean;

    private List<RightsAndInterestsReviceBean> list = new ArrayList<RightsAndInterestsReviceBean>();

    private GainOrderListBean gainOrderListBean;

    private List<GainOrderBean> listGainOrder = new ArrayList<GainOrderBean>();

    private List<ChildBean> listChild = new ArrayList<ChildBean>();

    private List<List<ChildBean>> listChild2 = new ArrayList<List<ChildBean>>();

    private List<PrantBean> listPrant = new ArrayList<PrantBean>();

    private PrantBean prantBean;

    private String areaName = "";

    private View view;

    private ImageView image;

    

    private OrderFromBean orderFromBean;

    private List<AccessAreaAndPriceBean> listAreaAndPrice = new ArrayList<AccessAreaAndPriceBean>();

    private AccessAreaAndPriceListBean accessAreaAndPriceListBean;

    @Override

    public void init() {

        setContentView(R.layout.ac_my_account);

        initView();

        initData();

        setListener();

    }

    // 加载布局

    public void initView() {

        flMyAccountGoBack = (FrameLayout) findViewById(R.id.fl_my_account_goback);

        ivMyAccountGoBack = (ImageView) findViewById(R.id.iv_my_account_goback);

        tvMyAccountPhone = (TextView) findViewById(R.id.tv_my_account_phone);

        tvMyAccountType = (TextView) findViewById(R.id.tv_my_account_type);

        MyAccoutMyRights = (NoScrollListView2) findViewById(R.id.lv_my_accout_my_rights);

        rlAccountShowMore = (RelativeLayout) findViewById(R.id.rl_account_show_more);

        tvAccountShowMore = (TextView) findViewById(R.id.tv_account_show_more);

        myAccoutUnpaidOrders = (NoScrollListView) findViewById(R.id.lv_my_accout_unpaid_orders);

        ll_no_history = (LinearLayout) findViewById(R.id.ll_no_history);

        ll_buy_history = (LinearLayout) findViewById(R.id.ll_buy_history);

        tv_buy_now = (TextView) findViewById(R.id.tv_buy_now);

 

    }

    // 加载数据

    public void initData() {

        BaseShareference baseShareference = new BaseShareference(

                MyAccountActivity.this);

        tvMyAccountPhone.setText("" + baseShareference.getUserName());

        if (baseShareference.getUserType().equals(1)) {

            tvMyAccountType.setText("个人未付费用户");

        }

        if (baseShareference.getUserType().equals(2)) {

            tvMyAccountType.setText("个人已付费用户");

        }

        if (baseShareference.getUserType().equals(3)) {

            tvMyAccountType.setText("企业用户主账号");

        }

        if (baseShareference.getUserType().equals(4)) {

            tvMyAccountType.setText("企业用户子账号");

        }

        rightsAndInterestsBean = new RightsAndInterestsBean();

        rightsAndInterestsBean.accessToken = MyApplication.getInstance().access_token;

        new BaseCommonAsyncTask(MyAccountActivity.this,

                new OnCommonPostSuccessListener() {

                    @Override

                    public void onPostSuccess(int action, JsonResult result) {

                        if (action == 0) {

                            return;

                        }

                        rightsAndInterestsListBean = (RightsAndInterestsListBean) result.data;

                        if (rightsAndInterestsListBean != null) {

                            if ("true".equals(result.success)) {

                                if (rightsAndInterestsListBean != null

                                        && rightsAndInterestsListBean.appData != null

                                        && rightsAndInterestsListBean.appData

                                                .size() > 0) {

                                    tvAccountShowMore.setVisibility(View.VISIBLE);

                                    ll_no_history.setVisibility(View.GONE);

                                    list = rightsAndInterestsListBean.appData;

                                    madapter = new MyAccountMyRightsAdapter(

                                            MyAccountActivity.this, list);

                                    if (list.size() <= 3) {

                                        madapter.setSize(list.size());

                                        tvAccountShowMore.setCompoundDrawables(

                                                null, null, null, null);

                                    } else {

                                        madapter.setSize(3);

                                    }

                                    MyAccoutMyRights.setAdapter(madapter);

                                    fixListViewHeight(MyAccoutMyRights);

                                    // ll_no_history.setVisibility(View.GONE);

                                    // ll_buy_history.setVisibility(View.VISIBLE);

                                } else {

                                    // ll_no_history.setVisibility(View.VISIBLE);

                                    // ll_buy_history.setVisibility(View.GONE);

                                    tvAccountShowMore.setVisibility(View.GONE);

                                    ll_no_history.setVisibility(View.VISIBLE);

                                    tvAccountShowMore.setCompoundDrawables(

                                            null, null, null, null);

                                }

                                tvAccountShowMore.setText("全部" + list.size()

                                        + "条");

                                HttpOrderList();

                            } else {

                                Toast.makeText(MyAccountActivity.this,

                                        rightsAndInterestsListBean.content,

                                        Toast.LENGTH_SHORT).show();

                            }

                        }

                    }

                }, 352, RightsAndInterestsListBean.class)

                .execute(rightsAndInterestsBean);

    }

    public void HttpOrderList() {

        rightsAndInterestsBean = new RightsAndInterestsBean();

        rightsAndInterestsBean.accessToken = MyApplication.getInstance().access_token;

        rightsAndInterestsBean.pageSize = 200;

        rightsAndInterestsBean.pageIndex = 1;

        new BaseCommonAsyncTask(MyAccountActivity.this,

                new OnCommonPostSuccessListener() {

                    @Override

                    public void onPostSuccess(int action, JsonResult result) {

                        if (action == 0) {

                            return;

                        }

                        gainOrderListBean = (GainOrderListBean) result.data;

                        if (gainOrderListBean != null) {

                            if ("true".equals(result.success)) {

                                if (gainOrderListBean != null

                                        && gainOrderListBean.appData != null

                                        && gainOrderListBean.appData.size() > 0) {

                                    //从后台请求的数据放到listChild2,这里就是子数据的集合。

                                    listChild2 = new ArrayList<List<ChildBean>>();

                                   //从后台请求的数据放到listPrant,这里就是父数据的集合。

                                    listPrant = new ArrayList<PrantBean>();

                                    listGainOrder = gainOrderListBean.appData;

                                    for (int i = 0; i < listGainOrder.size(); i++) {

                                        listChild = listGainOrder.get(i).detailList;

                                        prantBean = new PrantBean();

                                        for (int j = 0; j < listChild.size(); j++) {

                                            if (listChild.size() > 1) {

                                                areaName += listChild.get(j).locationName

                                                        + "、";

                                            } else {

                                                areaName += listChild.get(j).locationName;

                                            }

                                        }

                                        prantBean.locationName = areaName;

                                        prantBean.orderType = listGainOrder

                                                .get(i).orderType;

                                        prantBean.orderNo = listGainOrder

                                                .get(i).orderNo;

                                        areaName = "";

                                        prantBean.totalPrice = listGainOrder

                                                .get(i).totalPrice;

                                        listPrant.add(prantBean);// 父

                                        listChild2.add(listChild);

                                    

                                    }

                         

                                }

                            } else {

                                Toast.makeText(MyAccountActivity.this, "错误",

                                        Toast.LENGTH_SHORT).show();

                            }

                           //把子数据和父数据的集合给mUnPaidAdapter

                            mUnPaidAdapter = new MyAccountUnpaidOrdersAdapter(

                                    MyAccountActivity.this, listPrant,

                                    listChild2);

                            myAccoutUnpaidOrders.setAdapter(mUnPaidAdapter);

                            fixListViewHeight(myAccoutUnpaidOrders);

                        }

                    }

                }, 355, GainOrderListBean.class)

                .execute(rightsAndInterestsBean);

    }

    @Override

    public void setListener() {

        flMyAccountGoBack.setOnClickListener(this);

        ivMyAccountGoBack.setOnClickListener(this);

        rlAccountShowMore.setOnClickListener(this);

        tvAccountShowMore.setOnClickListener(this);

        tv_buy_now.setOnClickListener(this);

    }

    @Override

    public void onClick(View v) {

        switch (v.getId()) {

        case R.id.rl_account_show_more:

            if (isShowMore == false) {

                if (list.size() <= 3) {

                    tvAccountShowMore.setCompoundDrawables(null, null, null,

                            null);

                } else {

                    Drawable rdrawable = getResources().getDrawable(

                            R.drawable.project_detail_down);

                    rdrawable.setBounds(0, 0, rdrawable.getMinimumWidth(),

                            rdrawable.getMinimumHeight());

                    tvAccountShowMore.setCompoundDrawables(null, null,

                            rdrawable, null);

                }

                isShowMore = true;

                if (madapter != null) {

                    madapter.setSize(list.size());

                    madapter.notifyDataSetChanged();

                    fixListViewHeight(MyAccoutMyRights);

                }

            } else {

                if (list.size() <= 3) {

                    tvAccountShowMore.setCompoundDrawables(null, null, null,

                            null);

                } else {

                    Drawable rdrawable = getResources().getDrawable(

                            R.drawable.project_detail_up);

                    rdrawable.setBounds(0, 0, rdrawable.getMinimumWidth(),

                            rdrawable.getMinimumHeight());

                    tvAccountShowMore.setCompoundDrawables(null, null,

                            rdrawable, null);

                }

                isShowMore = false;

                if (madapter != null) {

                    if (list.size() <= 3) {

                        madapter.setSize(list.size());

                    } else {

                        madapter.setSize(3);

                    }

                    madapter.notifyDataSetChanged();

                    fixListViewHeight(MyAccoutMyRights);

                }

            }

            break;

        case R.id.tv_account_show_more:

            if (isShowMore == false) {

                if (list.size() <= 3) {

                    tvAccountShowMore.setCompoundDrawables(null, null, null,

                            null);

                } else {

                    Drawable rdrawable = getResources().getDrawable(

                            R.drawable.project_detail_down);

                    rdrawable.setBounds(0, 0, rdrawable.getMinimumWidth(),

                            rdrawable.getMinimumHeight());

                    tvAccountShowMore.setCompoundDrawables(null, null,

                            rdrawable, null);

                }

                isShowMore = true;

                if (madapter != null) {

                    madapter.setSize(list.size());

                    madapter.notifyDataSetChanged();

                    fixListViewHeight(MyAccoutMyRights);

                }

            } else {

                if (list.size() <= 3) {

                    tvAccountShowMore.setCompoundDrawables(null, null, null,

                            null);

                } else {

                    Drawable rdrawable = getResources().getDrawable(

                            R.drawable.project_detail_up);

                    rdrawable.setBounds(0, 0, rdrawable.getMinimumWidth(),

                            rdrawable.getMinimumHeight());

                    tvAccountShowMore.setCompoundDrawables(null, null,

                            rdrawable, null);

                }

                isShowMore = false;

                if (madapter != null) {

                    if (list.size() < 3) {

                        madapter.setSize(list.size());

                    } else {

                        madapter.setSize(3);

                    }

                    madapter.notifyDataSetChanged();

                    fixListViewHeight(MyAccoutMyRights);

                }

            }

            break;

        case R.id.tv_buy_now:

            

            orderFromBean = new OrderFromBean();

            if (MyApplication.getInstance().access_token != null) {

                orderFromBean.accessToken = MyApplication.getInstance().access_token;

            }

            new BaseCommonAsyncTask(MyAccountActivity.this,

                    new OnCommonPostSuccessListener() {

                        

                        @Override

                        public void onPostSuccess(int action, JsonResult result) {

                            if (action == 0) {

                                return;

                            }

                            accessAreaAndPriceListBean = (AccessAreaAndPriceListBean) result.data;

                            if (accessAreaAndPriceListBean != null) {

                                if ("true".equals(result.success)) {

                                    if (accessAreaAndPriceListBean != null

                                            && accessAreaAndPriceListBean.appData != null

                                            && accessAreaAndPriceListBean.appData

                                                    .size() > 0) {

                                        listAreaAndPrice = accessAreaAndPriceListBean.appData;

                                        Intent intent1 = new Intent(MyAccountActivity.this,BuyActivity.class);

                                        intent1.putExtra("listAreaAndPrice", (Serializable) listAreaAndPrice);

                                        intent1.putExtra("tag", "2");

                                        intent1.putExtra("name", "");

                                        startActivity(intent1);

                                        finish();

                                    } else {

                                        Toast.makeText(MyAccountActivity.this,

                                                accessAreaAndPriceListBean.content,

                                                Toast.LENGTH_SHORT).show();

                                    }

                                }

                                

                            }

                        }

                    }, 347, AccessAreaAndPriceListBean.class)

                    .execute(orderFromBean);

            break;

        case R.id.fl_my_account_goback:

            finish();

            break;

        case R.id.iv_my_account_goback:

            finish();

            break;

        default:

            break;

        }

        super.onClick(v);

    }

    @Override

    protected void onResume() {

        initData();

        isShowMore = false;

        super.onResume();

    }

}

//adapter,主要

MyAccountUnpaidOrdersAdapter.java:

package com.gldjc.gcsupplier.adapter;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

import com.gldjc.gcsupplier.MyApplication;

import com.gldjc.gcsupplier.R;

import com.gldjc.gcsupplier.account.activity.MyAccountActivity;

import com.gldjc.gcsupplier.activitys.BuyActivity;

import com.gldjc.gcsupplier.activitys.HomeActivity;

import com.gldjc.gcsupplier.activitys.WebViewCopyActivity;

import com.gldjc.gcsupplier.beans.AccessAreaAndPriceBean;

import com.gldjc.gcsupplier.beans.AccessAreaAndPriceListBean;

import com.gldjc.gcsupplier.beans.ChildBean;

import com.gldjc.gcsupplier.beans.JsonResult;

import com.gldjc.gcsupplier.beans.OrderFromBean2;

import com.gldjc.gcsupplier.beans.OrderFromSendBean;

import com.gldjc.gcsupplier.beans.PrantBean;

import com.gldjc.gcsupplier.beans.UriBean;

import com.gldjc.gcsupplier.interfaces.OnCommonPostSuccessListener;

import com.gldjc.gcsupplier.net.BaseCommonAsyncTask;

import com.gldjc.gcsupplier.util.BuriedPointUtil;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.graphics.drawable.Drawable;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewGroup.LayoutParams;

import android.widget.BaseAdapter;

import android.widget.BaseExpandableListAdapter;

import android.widget.Button;

import android.widget.ExpandableListView;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

public class MyAccountUnpaidOrdersAdapter extends BaseExpandableListAdapter{

    /** 上下文 */

    private Activity mContext;

    /** 存储父数据 */

    private List<PrantBean> groupList;

    /** 存储子数据 */

    private List<List<ChildBean>> childList;

    private List<AccessAreaAndPriceBean> listAreaAndPrice = new ArrayList<AccessAreaAndPriceBean>();

    private AccessAreaAndPriceListBean accessAreaAndPriceListBean;

    private OrderFromSendBean orderFromSendBean;

    

    private List<ChildBean> listForm;

    private UriBean uriBean;

    /** 构造函数 */

    public MyAccountUnpaidOrdersAdapter(Activity context,

            List<PrantBean> groupList, List<List<ChildBean>> childList) {

        this.mContext = context;

        this.groupList = groupList;

        this.childList = childList;

     

    }

 

    @Override

    public Object getChild(int groupPosition, int childPosition) {

        return childList.get(groupPosition).get(childPosition);

    }

  /*

    取得给定分组中给定子视图的.该组ID必须在组中是唯一的,必须不同于其他所有Id

    groupPosition:包含子视图分组的位置。

    childPosition:指定的分组中的子视图位置

   */

    @Override

    public long getChildId(int groupPosition, int childPosition) {

        return childPosition;

    }

    @Override

    public int getChildrenCount(int groupPosition) {

        return childList.get(groupPosition).size();

    }

    /**

     * 得到一个子view的实例

     *

     * @param groupPosition

     *            父view位置

     * @param childPosition

     *            子view位置

     * @param isLastChild

     *            是否为最后一个child

     * @param convertView

     *            转换view

     * @param parent

     *            父view

     * @return View textView的实例

     */

    @SuppressLint("ResourceAsColor")

    @Override

    public View getChildView(final int groupPosition, final int childPosition,

            boolean isLastChild, View convertView, ViewGroup parent) {

        ChildViewholder viewHolder = null;

        

        if(convertView == null){

            viewHolder = new ChildViewholder();

            convertView = View.inflate(mContext, R.layout.child_item_my_account_unpaid_orders,null);

            viewHolder.child_tv_unpaid_area_names = (TextView) convertView.findViewById(R.id.child_tv_unpaid_area_names);

            viewHolder.child_month_count = (TextView) convertView.findViewById(R.id.child_month_count);

            viewHolder.child_price = (TextView) convertView.findViewById(R.id.child_price);

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ChildViewholder) convertView.getTag();

        }

        viewHolder.child_tv_unpaid_area_names.setText(""+childList.get(groupPosition).get(childPosition).locationName);

        viewHolder.child_month_count.setText("购买"+childList.get(groupPosition).get(childPosition).monthCount+"个月");

        viewHolder.child_price.setText("单价"+childList.get(groupPosition).get(childPosition).price+"元");

        return convertView;

    }

    /**

     * 写这个是要封装item里面要用到的控件,并且与convertview绑定

     *

     * @author glodon

     *

     */

    class ChildViewholder {

        TextView child_tv_unpaid_area_names;

        TextView child_month_count;

        TextView child_price;

    }

    /**

     * 通过位置获取Object

     *

     * @param groupPosition

     *            view位置

     * @return Object 父view中对应位置的Object

     */

    @Override

    public Object getGroup(int groupPosition) {

        return groupList.get(groupPosition);

    }

    @Override

    public int getGroupCount() {

        return groupList.size();

    }

    @Override

    public long getGroupId(int groupPosition) {

        return groupPosition;

    }

    /**

     * 得到一个父view的实例

     *

     * @param groupPosition

     *            组位置

     * @param isExpanded

     *            是否展开

     * @param convertView

     *            转换view

     * @param parent

     *            父view

     * @return View textView的实例

     */

    @Override

    public View getGroupView(final int groupPosition, boolean isExpanded,

            View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        

        if(convertView == null){

            viewHolder = new ViewHolder();

            convertView = View.inflate(mContext, R.layout.item_my_account_unpaid_orders,null);

            viewHolder.unpaidAreaNames = (TextView) convertView.findViewById(R.id.tv_unpaid_area_names);

            viewHolder.unpaidSurplusDays = (TextView) convertView.findViewById(R.id.tv_unpaid_surplus_days);

            viewHolder.continuePay = (TextView) convertView.findViewById(R.id.tv_continue_pay);

            viewHolder.image = (ImageView) convertView.findViewById(R.id.image_image);

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.unpaidAreaNames.setText(""+groupList.get(groupPosition).locationName);

        viewHolder.unpaidSurplusDays.setText(groupList.get(groupPosition).totalPrice+"");
       //// 可以根据isExpanded来设置图片

         if(isExpanded){

              viewHolder.image.setBackgroundResource(R.drawable.project_detail_down);

         }else{

             viewHolder.image.setBackgroundResource(R.drawable.project_detail_up);

         }

        viewHolder.continuePay.setOnClickListener(new View.OnClickListener() {

            

            @Override

            public void onClick(View arg0) {

                BuriedPointUtil.statisticUserBehavior(mContext, "4003", null);

                

                orderFromSendBean = new OrderFromSendBean();

                orderFromSendBean.accessToken = MyApplication.getInstance().access_token;

                orderFromSendBean.orderNo = groupList.get(groupPosition).orderNo;

                new BaseCommonAsyncTask(mContext,

                        new OnCommonPostSuccessListener() {

                            @Override

                            public void onPostSuccess(int action,

                                    JsonResult result) {

                                if (action == 0) {

                                    return;

                                }

                                uriBean = (UriBean) result.data;

                                if (uriBean != null) {

                                    if ("true".equals(result.success)) {

                                        if (uriBean != null

                                                && uriBean.url != null) {

                                            String url = uriBean.url;

                                            Intent intent1 = new Intent(

                                                    mContext,

                                                    WebViewCopyActivity.class);

                                            intent1.putExtra(

                                                    "Key_activity_Url", url);

                                            mContext.startActivity(intent1);

                                            mContext.finish();

                                        } else {

                                            Toast.makeText(

                                                    mContext,

                                                    accessAreaAndPriceListBean.content,

                                                    Toast.LENGTH_SHORT)

                                                    .show();

                                        }

                                    }

                                }

                            }

                        }, 359, UriBean.class).execute(orderFromSendBean);

            }

        });

//        

        

    

        return convertView;

    }

    class GroupViewHolder {

        TextView nameTV;

        ImageView indicatorIV;

    }

    /**

     * 通知ListView, id是唯一的. 不会重复

     *

     * @param null

     * @return null

     */

    @Override

    public boolean hasStableIds() {

        return true;

    }

    /**

     * 设置子view点击触发为允许

     *

     * @param null

     * @return null

     */

    @Override

    public boolean isChildSelectable(int groupPosition, int childPosition) {

        return true;

    }

    @Override

    public void notifyDataSetChanged() {

        super.notifyDataSetChanged();

    }

    

    

    public class ViewHolder

    {

        private TextView unpaidAreaNames;//城市

        private TextView unpaidSurplusDays;//未支付的天数

        private TextView continuePay;//继续购买按钮

        private ImageView image;

    }

    

}

        

        
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: