main
package com.example.xandg; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class ThirdActivity extends AppCompatActivity { private TextView money; private Button xiadan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); Intent intent = getIntent(); String price = intent.getStringExtra("price"); money = (TextView) findViewById(R.id.money); money.setText("实付款:¥"+price); xiadan = (Button) findViewById(R.id.xiadan); xiadan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent1 = new Intent(ThirdActivity.this,FourActivity.class); startActivity(intent1); } }); } }
aitivity
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.xandg.ThirdActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" > <TextView android:id="@+id/money" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:text="实付款:¥" /> <Button android:id="@+id/xiadan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="立即下单" android:background="#ff0000" /> </LinearLayout> </RelativeLayout>
secondactivity
package com.example.xandg; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import java.util.List; import bean.GetCartBean; import bean.PriceAndCount; import presenter.ElvAdapter; import presenter.GetCartPresenter; import presenter.ICartView; public class SecondActivity extends AppCompatActivity implements ICartView{ private ExpandableListView mElv; /** * 全选 */ private CheckBox mCb; /** * 合计: */ private TextView mTvTotal; /** * 去结算(0) */ private TextView mTvCount; private GetCartPresenter presenter; private ElvAdapter elvAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); initView(); presenter = new GetCartPresenter(this); presenter.getNews(); mCb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { elvAdapter.AllOrNone(mCb.isChecked()); } }); } private void initView() { mElv = (ExpandableListView) findViewById(R.id.elv); mCb = (CheckBox) findViewById(R.id.cb); mTvTotal = (TextView) findViewById(R.id.tvTotal); mTvCount = (TextView) findViewById(R.id.tvCount); } @Override public void show(List<GetCartBean.DataBean> group, List<List<GetCartBean.DataBean.ListBean>> child) { elvAdapter = new ElvAdapter(this,group,child); mElv.setGroupIndicator(null); mElv.setAdapter(elvAdapter); for (int i = 0; i < group.size(); i++) { mElv.expandGroup(i); } } public void setPriceAndCount(final PriceAndCount priceAndCount) { mTvTotal.setText("合计:" + priceAndCount.getPrice()); mTvCount.setText("去结算(" + priceAndCount.getCount() + ")"); mTvCount.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SecondActivity.this,ThirdActivity.class); intent.putExtra("price",priceAndCount.getPrice()+""); startActivity(intent); } }); } public void setAllChecked(boolean bool) { mCb.setChecked(bool); } }
second/xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.xandg.SecondActivity" android:orientation="vertical" > <ExpandableListView android:id="@+id/elv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <CheckBox android:id="@+id/cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="全选" /> <TextView android:id="@+id/tvTotal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@id/cb" android:text="合计:" /> <TextView android:id="@+id/tvCount" android:layout_width="100dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="#ff0000" android:gravity="center" android:text="去结算(0)" android:textColor="#ffffff" /> </RelativeLayout> </LinearLayout>