public classMainActivityextendsAppCompatActivity {
privateBannerbanner;
privateViewPagerviewPager;
privateTabLayouttabLayout;
privateListfragmentList;
privateListlist;
privateListimagelist;
privateString[]str={"热门","分类","作者"};
privateHandlerhandler=newHandler() {
@Override
public voidhandleMessage(Message msg) {
String s = msg.obj.toString();
Gson gson =newGson();
News news = gson.fromJson(s,News.class);
List been = news.getData().getInfos().get(0).getBanners();
imagelist=newArrayList<>();
for(News.DataBean.InfosBean.BannersBean bean : been) {
imagelist.add(bean.getPic());
}
banner.setImages(imagelist);
banner.start();
}
};
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager= (ViewPager) findViewById(R.id.viewpager);
tabLayout= (TabLayout) findViewById(R.id.tab);
banner= (Banner) findViewById(R.id.banner);
banner.setImageLoader(newImageL(this));
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
banner.setIndicatorGravity(BannerConfig.CENTER);
banner.setOnBannerListener(newOnBannerListener() {
@Override
public voidOnBannerClick(intposition) {
Intent intent=newIntent(MainActivity.this,Main2Activity.class);
intent.putExtra("image",imagelist.get(position%imagelist.size()));
startActivity(intent);
}
});
Nee();
add();
newThread() {
@Override
public voidrun() {
String urlConnect = Net.getUrlConnect("http://api.kkmh.com/v1/topic_new/discovery_list?gender=0&sa_event=eyJwcm9qZWN0Ijoia3VhaWthbl9hcHAiLCJ0aW1lIjoxNDg3ODM5MDM5MzE1LCJwcm9wZXJ0aWVzIjp7IkhvbWVwYWdlVGFiTmFtZSI6IueDremXqCIsIlZDb21tdW5pdHlUYWJOYW1lIjoi54Ot6ZeoIiwiJG9zX3ZlcnNpb24iOiI0LjIuMiIsIkdlbmRlclR5cGUiOiLlpbPniYgiLCJGcm9tRmluZENhdGVnb3J5VGFiTmFtZSI6IuWFqOmDqCIsIklzQXV0b0xvYWQiOmZhbHNlLCIkbGliX3ZlcnNpb24iOiIxLjYuMzQiLCIkbmV0d29ya190eXBlIjoiV0lGSSIsIiR3aWZpIjp0cnVlLCIkbWFudWZhY3R1cmVyIjoic2Ftc3VuZyIsIkZyb21GaW5kVGFiTmFtZSI6IuaOqOiNkCIsIiRzY3JlZW5faGVpZ2h0Ijo1NzYsIkNhdGVnb3J5Ijoi5peg5rOV6I635Y-WIiwiSG9tZXBhZ2VVcGRhdGVEYXRlIjowLCJQcm9wZXJ0eUV2ZW50IjoiUmVhZEZpbmRQYWdlIiwiRmluZFRhYk5hbWUiOiLmjqjojZAiLCJhYnRlc3RfZ3JvdXAiOjQ2LCIkc2NyZWVuX3dpZHRoIjoxMDI0LCJGaW5kQ2F0ZWdvcnlUYWJOYW1lIjoi5YWo6YOoIiwiJG9zIjoiQW5kcm9pZCIsIlRyaWdnZXJQYWdlIjoiSG9tZVBhZ2UiLCIkY2FycmllciI6IkNNQ0MiLCIkbW9kZWwiOiJHVC1QNTIxMCIsIiRhcHBfdmVyc2lvbiI6IjMuOC4xIn0sInR5cGUiOiJ0cmFjayIsImRpc3RpbmN0X2lkIjoiQTo5MDUxMDQyNzYzNzU1MTA5Iiwib3JpZ2luYWxfaWQiOiJBOjkwNTEwNDI3NjM3NTUxMDkiLCJldmVudCI6IlJlYWRGaW5kUGFnZSJ9");
// if(urlConnect==null)
// return;
Message message = Message.obtain();
message.obj= urlConnect;
handler.sendMessage(message);
}
}.start();
}
private voidNee() {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.newTab().setText("热门");
tabLayout.newTab().setText("分类");
tabLayout.newTab().setText("作者");
add();
Adapter adapter =newAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
}
private voidadd() {
fragmentList=newArrayList<>();
fragmentList.add(newOne());
fragmentList.add(newTwo());
fragmentList.add(newThree());
}
classAdapterextendsFragmentPagerAdapter {
publicAdapter(FragmentManager fm) {
super(fm);
}
@Override
publicFragmentgetItem(intposition) {
returnfragmentList.get(position);
}
@Override
public intgetCount() {
returnfragmentList.size();
}
@Override
publicCharSequencegetPageTitle(intposition) {
// if (position == 0)
// return "热门";
// if (position == 1)
// return "分类";
// if (position == 2)
// return "作者";
returnstr[position];
}
}
}
网友评论