package com.lbp.yuekao.view;
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 com.lbp.yuekao.R;
import com.lbp.yuekao.adapter.MyAdapter;
import com.lbp.yuekao.adapter.MyExAdapter;
import com.lbp.yuekao.bean.GoosBean;
import com.lbp.yuekao.bean.MessageEvent;
import com.lbp.yuekao.bean.PriceAndCountEvent;
import com.lbp.yuekao.presenter.MainPresenter;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.List;
public class ContextActivity extends AppCompatActivity implements IContextView {
private ExpandableListView elv;
private TextView tv_num;
private TextView tv_price;
private CheckBox checkBox2;
private MyExAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_context);
initViews();
new MainPresenter(this).getGoods();
checkBox2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
adapter.changeAllListCbState(checkBox2.isChecked());
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
private void initViews() {
elv = (ExpandableListView) findViewById(R.id.elv);
checkBox2 = (CheckBox) findViewById(R.id.checkbox2);
tv_price = (TextView) findViewById(R.id.tv_price);
tv_num = (TextView) findViewById(R.id.tv_num);
}
@Override
public void showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList) {
adapter = new MyExAdapter(this, groupList, childList);
elv.setAdapter(adapter);
elv.setGroupIndicator(null);
//默认让其全部展开
for (int i = 0; i < groupList.size(); i++) {
elv.expandGroup(i);
}
}
@Subscribe
public void onMessageEvent(MessageEvent event) {
checkBox2.setChecked(event.isChecked());
}
@Subscribe
public void onMessageEvent(PriceAndCountEvent event) {
tv_num.setText("结算(" + event.getCount() + ")");
tv_price.setText(event.getPrice() + "");
}
}
view层
package com.lbp.yuekao.view;
import com.lbp.yuekao.bean.GoosBean;
import java.util.List;
/**
* Created by Administrator on 2018/1/17 0017.
*/
public interface IContextView {
void showList(List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList);
}