package com.bwei.headline; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.bawei.channelmanager.bean.ChannelBean; import com.bawei.channelmanager.ui.ChannelView; import java.util.ArrayList; import java.util.List; public class ChannelActivity extends AppCompatActivity implements View.OnClickListener { private ImageView iv_back; private TextView edit; private ChannelView channe_view; // 存放频道的List private List<ChannelBean> loveChannel = new ArrayList<>(); private List<ChannelBean> moreChannel = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_channel); initView(); getServer(); } private void initView() { iv_back = (ImageView) findViewById(R.id.iv_back); edit = (TextView) findViewById(R.id.edit); channe_view = (ChannelView) findViewById(R.id.channe_view); } private void getServer() { iv_back.setOnClickListener(this); edit.setOnClickListener(this); channe_view.addHead(View.inflate(this,R.layout.channel_head,null)); channe_view.addMore(View.inflate(this,R.layout.channel_more,null)); // 初始化数据 for (int i = 0; i < 20; i++) { if(i % 2 == 0) { loveChannel.add(new ChannelBean("费晓萱" + i, i, "http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1", true)); } else { moreChannel.add(new ChannelBean("曲学超" + i, i, "http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1", false)); } } // channelView的优化 channe_view.init(loveChannel, moreChannel, new ChannelView.ChannelCallback() { @Override public void onMyChannelRemove(ChannelBean channelBean) { } @Override public void moMoreChannelRemove(ChannelBean channelBean) { } }); } private boolean channelState; @Override public void onClick(View view) { switch (view.getId()){ case R.id.iv_back: finish(); break; case R.id.edit: if (!channelState){ edit.setText("完成"); } else { edit.setText("编辑"); } channe_view.changeMyChannelState(); channelState = !channelState; break; } } }