/** * 获取控件 */MyHorizontalTabhost tabhost = (MyHorizontalTabhost) findViewById(R.id.tabhost);/** * 频道管理 */jiantou = (ImageView) findViewById(R.id.jiantou);jiantou.setOnClickListener(new View.OnClickListener() { private List<ChannelBean> list1; @Override public void onClick(View view) { list1 = new ArrayList<ChannelBean>(); ChannelBean channelBean; SharedPreferences sp=getSharedPreferences("config",MODE_PRIVATE); String json = sp.getString("json", null); if(json!=null) { try { JSONArray result=new JSONArray(json); for (int i = 0; i < result.length(); i++) { JSONObject resultBean = (JSONObject) result.get(i); String name = resultBean.getString("name"); boolean isSelect = resultBean.getBoolean("isSelect"); ChannelBean channel=new ChannelBean(name,isSelect); list1.add(channel); } } catch (JSONException e) { e.printStackTrace(); } }else { channelBean=new ChannelBean("头条",true); ChannelBean channelBean2=new ChannelBean("国内",true); ChannelBean channelBean3=new ChannelBean("国际",true); ChannelBean channelBean4=new ChannelBean("娱乐",true); ChannelBean channelBean5=new ChannelBean("时尚",true); ChannelBean channelBean6=new ChannelBean("体育",true); ChannelBean channelBean7=new ChannelBean("军事",true); ChannelBean channelBean8=new ChannelBean("科技",true); ChannelBean channelBean9=new ChannelBean("财经",true); ChannelBean channelBean10=new ChannelBean("社会",true); list1.add(channelBean); list1.add(channelBean2); list1.add(channelBean3); list1.add(channelBean4); list1.add(channelBean5); list1.add(channelBean6); list1.add(channelBean7); list1.add(channelBean8); list1.add(channelBean9); list1.add(channelBean10); } ChannelActivity.startChannelActivity(MainActivity.this,list1); }});public void parseDate(String json) { list.clear(); newfragments = new ArrayList<>(); try { JSONArray result=new JSONArray(json); for (int i = 0; i < result.length(); i++) { JSONObject resultBean = (JSONObject) result.get(i); String name = resultBean.getString("name"); boolean isSelect = resultBean.getBoolean("isSelect"); if(isSelect==true) { list.add(name); newfragments.add(fragmentList.get(i)); } } } catch (JSONException e) { e.printStackTrace(); } tabhost.update(); tabhost.diaplay(list,fragmentList); }@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==101) { String json = data.getExtras().getString("json"); System.out.println(json); SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE); SharedPreferences.Editor editor=sp.edit(); editor.putString("json",json); editor.commit(); parseDate(json); } }
频道管理
最新推荐文章于 2019-01-16 19:55:59 发布