public class MainActivity extends AppCompatActivity { private List<ChannelBean> list; private String jsonStr; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (list==null){//判断集合中是否已有数据,没有则创建 list=new ArrayList<>(); //第一个是显示的条目,第二个参数是否显示 list.add(new ChannelBean("热点",true)); list.add(new ChannelBean("军事",true)); list.add(new ChannelBean("八卦",true)); list.add(new ChannelBean("游戏",true)); list.add(new ChannelBean("宠物",true)); list.add(new ChannelBean("汽车",false)); list.add(new ChannelBean("热卖",false)); list.add(new ChannelBean("外卖",false)); list.add(new ChannelBean("太阳花",false)); list.add(new ChannelBean("九三",false)); list.add(new ChannelBean("八嘎",false)); list.add(new ChannelBean("色昂",false)); ChannelActivity.startChannelActivity(MainActivity.this,list); }else if (jsonStr!=null){//当判断保存的字符串不为空的时候,直接加载已经有了的字符串 ChannelActivity.startChannelActivity(MainActivity.this,jsonStr); } } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode==ChannelActivity.REQUEST_CODE&&resultCode==ChannelActivity.RESULT_CODE) { jsonStr = data.getStringExtra(ChannelActivity.RESULT_JSON_KEY); } } }
频道管理
首先在项目的build下注册
allprojects {
repositories {
jcenter()
//下面这句才是加上的,上面的自带 的
maven {url "https://jitpack.io"}
}
}
然后在app下的build中导入依赖
compile 'com.github.andyoom:draggrid:v1.0.1'
然后在main类中就可以使用了,只要用集合将数据添加就可以了