赞
踩
MainActivity
package wangxuewei.bwie.com.week3;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.RadioGroup;
import baseFragment.Fr_FaXian;
import baseFragment.Fr_ShouYe;
import baseFragment.Fr_WoDe;
import baseFragment.Fr_XiaZai;
public class MainActivity extends AppCompatActivity {
private DrawerLayout drawer_layout;
private RadioGroup rg;
private FrameLayout fr_main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//加载控件
initView();
setFragment(new Fr_ShouYe());
//设置监听
setListeners();
}
private void setListeners() {
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
switch (checkedId) {
case R.id.rb_shouye:
setFragment(new Fr_ShouYe());
break;
case R.id.rb_faxian:
setFragment(new Fr_FaXian());
break;
case R.id.rb_wode:
setFragment(new Fr_WoDe());
break;
case R.id.rb_xiazai:
setFragment(new Fr_XiaZai());
break;
}
}
});
}
private void initView() {
drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
rg = (RadioGroup) findViewById(R.id.rg);
fr_main = (FrameLayout) findViewById(R.id.fr_main);
}
private void setFragment(Fragment f) {
getSupportFragmentManager().beginTransaction().replace(R.id.fr_main, f).commit();
}
;
}
MyApplication
package wangxuewei.bwie.com.week3;
import android.app.Application;
import utils.ImageLoaderUtil;
/**
* Created by jim on 2017/10/21.
*/
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderUtil.initConfig(this);
}
}
ImageLoaderUtil
package utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import java.io.File;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class ImageLoaderUtil {
/**
* ImageLoader的配置
*
* @param context
*/
public static void initConfig(Context context) {
//配置
// File cacheFile=context.getExternalCacheDir();
File cacheFile = new File(Environment.getExternalStorageDirectory() + "/" + "images");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800)//缓存图片最大的长和宽
.threadPoolSize(2)//线程池的数量
.threadPriority(4)
.memoryCacheSize(2 * 1024 * 1024)//设置内存缓存区大小
.diskCacheSize(20 * 1024 * 1024)//设置sd卡缓存区大小
.diskCache(new UnlimitedDiscCache(cacheFile))//自定义缓存目录
.writeDebugLogs()//打印日志内容
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
.build();
ImageLoader.getInstance().init(config);
}
/**
* 获取图片设置类
*
* @return
*/
public static DisplayImageOptions getImageOptions() {
DisplayImageOptions optionsoptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)//使用内存缓存
.cacheOnDisk(true)//使用磁盘缓存
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片格式
.showImageOnLoading(R.mipmap.ic_launcher)//设置正在下载的图片
.showImageForEmptyUri(R.mipmap.ic_launcher)//url为空或请求的资源不存在时
.showImageOnFail(R.mipmap.ic_launcher)//下载失败时显示的图片
.displayer(new RoundedBitmapDisplayer(30))//设置圆角,参数代表度数
.build();
return optionsoptions;
}
}
MyTask
package utils;
import android.os.AsyncTask;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by jim on 2017/10/21.
*/
public class MyTask extends AsyncTask<String, Void, String> {
//申请一个接口类对象
private Icallbacks icallbacks;
//将无参构造设置成私有的,使之在外部不能够调用
private MyTask() {
}
//定义有参构造方法
public MyTask(Icallbacks icallbacks) {
this.icallbacks = icallbacks;
}
@Override
protected String doInBackground(String... params) {
String str = "";
try {
//使用HttpUrlConnection
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
if (connection.getResponseCode() == 200) {
InputStream inputStream = connection.getInputStream();
//调用工具类中的静态方法
str = StreamToString.streamToStr(inputStream, "utf-8");
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//解析,封装到bean,更新ui组件
icallbacks.updateUiByjson(s);
}
//定义一个接口
public interface Icallbacks {
/**
* 根据回传的json字符串,解析并更新页面组件
*
* @param jsonstr
*/
void updateUiByjson(String jsonstr);
}
}
StreamToString
package utils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by jim on 2017/10/21.
*/
public class StreamToString {
public static String streamToStr(InputStream inputStream, String chartSet) {
StringBuilder builder = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, chartSet));
String con;
while ((con = br.readLine()) != null) {
builder.append(con);
}
br.close();
return builder.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
Results
package baseBean;
import java.util.List;
/**
* Created by jim on 2017/10/21.
*/
public class Results {
/**
* status : 1
* info : 获取内容成功
* data : [{"news_id":"13811","news_title":"深港澳台千里连线,嘉年华会今夏入川","news_summary":"6月17\u201420日,\u201c2016成都深港澳台嘉年华会\u201d(简称嘉年华会)将在成都世纪城国际会展中心举办。其主办方励展华博借力旗","pic_url":"http://f.expoon.com/sub/news/2016/01/21/887844_230x162_0.jpg"},{"news_id":"13810","news_title":"第14届温州国际汽车展4月举行 设9大主题展馆","news_summary":"来自前不久举行的温州国际汽车展览会第一次新闻发布会的消息, 2016第14届温州国际汽车展览会定于4月7-10日在温州国","pic_url":"http://f.expoon.com/sub/news/2016/01/21/580828_230x162_0.jpg"},{"news_id":"13808","news_title":"第十二届中国(南安)国际水暖泵阀交易会 四大亮点","news_summary":"第十二届中国(南安)国际水暖泵阀交易会将于2月10日至12日(即农历正月初三至初五)在成功国际会展中心拉开帷幕。","pic_url":"http://f.expoon.com/sub/news/2016/01/21/745921_230x162_0.jpg"},{"news_id":"13805","news_title":"2016上海灯光音响展 商机无限,一触即发","news_summary":"2016上海国际专业灯光音响展即日起全面启动,海内外高端演艺设备商贸平台,商机无限,一触即发。6大洲,80个国家,25,","pic_url":"http://f.expoon.com/sub/news/2016/01/21/158040_230x162_0.jpg"},{"news_id":"13804","news_title":"第四届南京国际佛事展5月举行","news_summary":"2016年,\u201c第四届南京国际佛事文化用品展览会\u201d将于5月26-29日在南京国际展览中心举办。","pic_url":"http://f.expoon.com/sub/news/2016/01/21/865222_230x162_0.jpg"},{"news_id":"13802","news_title":"上海国际牛仔服装博览会 拓展国际贸易大市场","news_summary":"2016年第三届上海国际牛仔服装博览会将于4月19-21日再次璀璨再现上海世博展览馆,共同探讨牛仔流行趋势,诠释牛仔文化","pic_url":"http://f.expoon.com/sub/news/2016/01/20/370858_230x162_0.jpg"},{"news_id":"13800","news_title":"第三届兰州年货会在甘肃国际会展中心本月19日开幕","news_summary":"由中国商业联合会、甘肃省商业联合会、兰州市商务局主办,甘肃省酒类商品管理局、兰州市城关区商务局、第十四届西安年货会组委会","pic_url":"http://f.expoon.com/sub/news/2016/01/20/868385_230x162_0.jpg"},{"news_id":"13799","news_title":"首届移动拍卖艺术博览会启动","news_summary":"首届移动拍卖博览会已于2016年1月全面启动,由大咖拍卖主办,联合全国艺术机构共同打造拍卖艺术博览会主会场,近百场拍卖专","pic_url":"http://f.expoon.com/sub/news/2016/01/20/768695_230x162_0.jpg"},{"news_id":"13798","news_title":"武汉金融理财投资博览会将在5月举办","news_summary":"由武汉市贸促会、上海《理财周刊》社、湖北好博塔苏斯展览有限公司等单位联合发起的\u201c2016武汉金融理财投资博览会\u201d,将在武","pic_url":"http://f.expoon.com/sub/news/2016/01/20/512947_230x162_0.jpg"},{"news_id":"13796","news_title":"第三届中国微商博览会 3月底济南举办","news_summary":"2015年,沸点天下开创了微商行业第一个展会\u2014\u2014中国微商博览会,并于2015年成功举行两届,让微商展会从无到有,并且起了","pic_url":"http://f.expoon.com/sub/news/2016/01/20/348021_230x162_0.jpg"},{"news_id":"13793","news_title":"2016中国西部国际丝绸博览会","news_summary":"\u201c2016年中国西部国际丝绸博览会\u201d最新确定于2016年5月11日至15日在南充举行。据悉,\u201c丝博会\u201d的会徽、会标及宣传","pic_url":"http://f.expoon.com/sub/news/2016/01/19/113912_230x162_0.jpg"},{"news_id":"13792","news_title":"中国针棉织品交易会开拓\u201c西部市场\u201d","news_summary":"由国家商务部重点支持、中国纺织品商业协会主办的第98届中国针棉织品交易会将于3月15日~17日绽放成都。作为中国国内针棉","pic_url":"http://f.expoon.com/sub/news/2016/01/19/650175_230x162_0.jpg"},{"news_id":"13791","news_title":"乐山市第二十届房地产展示交易会开幕","news_summary":"美丽乐山,生态宜居。今日,乐山市第二十届房地产展示交易会在该市中心城区乐山广场开幕,展会将持续到1月24日。","pic_url":"http://f.expoon.com/sub/news/2016/01/19/321787_230x162_0.jpg"},{"news_id":"13790","news_title":"2016华中屋面与建筑防水技术展3月即将开幕","news_summary":"由湖北省建筑防水协会联合湖南、河南、江西、安徽五省建筑防水协会主办\u201c2016第二届华中屋面与建筑防水技术展览会\u201d将于20","pic_url":"http://f.expoon.com/sub/news/2016/01/19/376254_230x162_0.jpg"},{"news_id":"13789","news_title":"2016海南国际旅游贸易博览会召开新闻发布会","news_summary":"近日,三亚旅游官方网从海南省\u201c首届海博会\u201d新闻发布会上获悉,海南省\u201c首届海博会\u201d将于2016年3月26日至4月1日在三亚","pic_url":"http://f.expoon.com/sub/news/2016/01/19/958046_230x162_0.jpg"},{"news_id":"13788","news_title":"2016阿里巴巴·贵州年货节展销会开幕","news_summary":"\u201c2016阿里巴巴·贵州年货节\u201d的展销会及迎春庙会昨日启动。150多家餐饮商参与的美食节、近千个品种组成的年货展销会等,","pic_url":"http://f.expoon.com/sub/news/2016/01/19/371688_230x162_0.jpg"},{"news_id":"13787","news_title":"第二届中国盆栽花卉交易会\u200b 本月28日开幕","news_summary":"据广州市政府获悉,经中国花卉协会和广州市政府批准,第二届中国盆栽花卉交易会将于本月28日至31日在广州花卉博览园举行。届","pic_url":"http://f.expoon.com/sub/news/2016/01/18/687647_230x162_0.jpg"},{"news_id":"13786","news_title":"李益:视野、品质、融合是展览工程国际化的必由路径","news_summary":"\u201c视野、品质、融合是中国展览工程走向国际化的必由路径。\u201d北京逸格天骄国际展览有限公司副总经理李益日前在第二十二届国际(常","pic_url":"http://f.expoon.com/sub/news/2016/01/18/343556_230x162_0.jpg"},{"news_id":"13785","news_title":"第八届中国国际集成住宅产业博览会将于5月在广州举办","news_summary":"2016年1月14日,第八届中国(广州)国际集成住宅产业博览会暨2016亚太建筑科技论坛\u2014\u2014新闻发布会在广州馆隆重召开。","pic_url":"http://f.expoon.com/sub/news/2016/01/18/581830_230x162_0.jpg"},{"news_id":"13784","news_title":"丝绸之路敦煌国际文化博览会筹备工作进展顺利","news_summary":"近日,丝绸之路(敦煌)国际文化博览会组委会第二次会议在兰召开。会议研究讨论了省直厅局一对一服务保障沿线省区市方案、文博会","pic_url":"http://f.expoon.com/sub/news/2016/01/18/656693_230x162_0.jpg"}]
*/
private int status;
private String info;
private List<DataBean> data;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* news_id : 13811
* news_title : 深港澳台千里连线,嘉年华会今夏入川
* news_summary : 6月17—20日,“2016成都深港澳台嘉年华会”(简称嘉年华会)将在成都世纪城国际会展中心举办。其主办方励展华博借力旗
* pic_url : http://f.expoon.com/sub/news/2016/01/21/887844_230x162_0.jpg
*/
private String news_id;
private String news_title;
private String news_summary;
private String pic_url;
public String getNews_id() {
return news_id;
}
public void setNews_id(String news_id) {
this.news_id = news_id;
}
public String getNews_title() {
return news_title;
}
public void setNews_title(String news_title) {
this.news_title = news_title;
}
public String getNews_summary() {
return news_summary;
}
public void setNews_summary(String news_summary) {
this.news_summary = news_summary;
}
public String getPic_url() {
return pic_url;
}
public void setPic_url(String pic_url) {
this.pic_url = pic_url;
}
}
}
Fr_FaXian
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Fr_FaXian extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fr_others, null);
TextView text = (TextView) inflate.findViewById(R.id.text_others);
text.setText("发现界面");
return inflate;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Fr_ShouYe
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Fr_ShouYe extends Fragment {
private List<String> tab_list;
private List<Fragment> fr_list;
private TabLayout tab_layout;
private ViewPager vp;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fr_shouye, null);
tab_layout = (TabLayout) inflate.findViewById(R.id.tab_layout);
vp = (ViewPager) inflate.findViewById(R.id.vp);
//设置tab的值
initTab();
return inflate;
}
private void initTab() {
tab_list = new ArrayList<>();
tab_list.add("推荐");
tab_list.add("课程");
tab_list.add("实战");
tab_list.add("职业路径");
fr_list = new ArrayList<>();
fr_list.add(new Tab_Tuijian());
fr_list.add(new Tab_KeCheng());
fr_list.add(new Tab_ShiZhan());
fr_list.add(new Tab_ZhiYeLuJing());
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//设置适配器
vp.setAdapter(new TabAdapter(getChildFragmentManager()));
//进行关联
tab_layout.setupWithViewPager(vp);
//显示的页数
vp.setOffscreenPageLimit(fr_list.size());
}
//适配器
class TabAdapter extends FragmentPagerAdapter {
public TabAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return tab_list.get(position);
}
@Override
public Fragment getItem(int position) {
return fr_list.get(position);
}
@Override
public int getCount() {
return fr_list.size();
}
}
}
Fr_WoDe
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Fr_WoDe extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fr_others, null);
TextView text = (TextView) inflate.findViewById(R.id.text_others);
text.setText("我的界面");
return inflate;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Fr_XiaZai
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Fr_XiaZai extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fr_others, null);
TextView text = (TextView) inflate.findViewById(R.id.text_others);
text.setText("下载界面");
return inflate;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Tab_KeCheng
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Tab_KeCheng extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.vp_others, null);
TextView text = (TextView) v.findViewById(R.id.text_vpother);
text.setText("课程页面");
return v;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Tab_ShiZhan
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Tab_ShiZhan extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.vp_others, null);
TextView text = (TextView) v.findViewById(R.id.text_vpother);
text.setText("实战页面");
return v;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Tab_Tuijian
package baseFragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import java.util.ArrayList;
import java.util.List;
import adapter.ImgVpAdapter;
import adapter.LvAdapter;
import baseBean.Results;
import utils.MyTask;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Tab_Tuijian extends Fragment {
private List<String> img_list;
private ViewPager vp_img;
private int index = 0;
private int flag = 1;
private List<Results.DataBean> lists = new ArrayList<>();
private Handler myHandler = new Handler();
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0) {
index++;
vp_img.setCurrentItem(index);
handler.sendEmptyMessageDelayed(0, 2000);
}
}
};
private PullToRefreshListView ptr_lv;
private LvAdapter adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.vp_tuijian, null);
vp_img = (ViewPager) view.findViewById(R.id.vp_img);
ptr_lv = (PullToRefreshListView) view.findViewById(R.id.ptr_lv);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//设置无线轮播
setImgVp();
//初始化数据
getNetData();
//设置listView列表
setPtrListView();
}
//加载网络数据
private void getNetData() {
MyTask myTask = new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Gson gson = new Gson();
Results results = gson.fromJson(jsonstr, Results.class);
List<Results.DataBean> data = results.getData();
Log.i("wxw", data.size() + "++++++");
lists.addAll(data);
setAdapter();
}
});
myTask.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/1");
}
//刷新方法
private void addtoTop() {
lists.clear();
getNetData();
}
//加载方法
private void addtoBottom() {
MyTask myTask = new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Gson gson = new Gson();
Results results = gson.fromJson(jsonstr, Results.class);
List<Results.DataBean> data = results.getData();
Log.i("wxw", data.size() + "++++++");
lists.addAll(data);
setAdapter();
}
});
flag++;
myTask.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/" + flag);
}
//设置适配器
private void setAdapter() {
if (adapter == null) {
adapter = new LvAdapter(lists, getActivity());
ptr_lv.setAdapter(adapter);
} else {
adapter.notifyDataSetChanged();
}
}
private void setPtrListView() {
ptr_lv.setMode(PullToRefreshBase.Mode.BOTH);
//配置刷新的设置
ILoadingLayout startLabels = ptr_lv.getLoadingLayoutProxy(true, false);
startLabels.setPullLabel("下拉刷新");
startLabels.setRefreshingLabel("正在拉");
startLabels.setReleaseLabel("放开刷新");
ILoadingLayout endLabels = ptr_lv.getLoadingLayoutProxy(false, true);
endLabels.setPullLabel("上拉刷新");
endLabels.setRefreshingLabel("正在载入...");
endLabels.setReleaseLabel("放开刷新...");
//设置刷新的监听
ptr_lv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {//下拉刷新的回调
//下拉刷新的数据,显示在listview列表的最上面
addtoTop();
myHandler.postDelayed(new Runnable() {
@Override
public void run() {
//刷新完成,必须在异步下完成
ptr_lv.onRefreshComplete();
//刷新适配器
// setAdapter();
}
}, 1000);
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {//上拉加载的回调
//加载更多的数据,添加到集合列表的最后面
addtoBottom();
myHandler.postDelayed(new Runnable() {
@Override
public void run() {
//刷新完成,必须在异步下完成
ptr_lv.onRefreshComplete();
//刷新适配器
// setAdapter();
}
}, 1000);
}
});
}
private void setImgVp() {
//加载图片数据
img_list = new ArrayList<>();
img_list.add("http://pic8.nipic.com/20100701/5290458_114840036316_2.jpg");
img_list.add("http://pic2.nipic.com/20090424/1468853_230119053_2.jpg");
img_list.add("http://img3.3lian.com/2013/s1/20/d/57.jpg");
img_list.add("http://pic39.nipic.com/20140226/18071023_164300608000_2.jpg");
img_list.add("http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg");
vp_img.setAdapter(new ImgVpAdapter(img_list, getActivity()));
vp_img.setCurrentItem(index);
handler.sendEmptyMessageDelayed(0, 2000);
}
}
Tab_ZhiYeLuJing
package baseFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class Tab_ZhiYeLuJing extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.vp_others, null);
TextView text = (TextView) v.findViewById(R.id.text_vpother);
text.setText("职业路径页面");
return v;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
ImgVpAdapter
package adapter;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import utils.ImageLoaderUtil;
/**
* Created by jim on 2017/10/21.
*/
public class ImgVpAdapter extends PagerAdapter {
private List<String> list;
private Context context;
public ImgVpAdapter(List<String> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
ImageLoader.getInstance().displayImage(list.get(position % list.size()), imageView, ImageLoaderUtil.getImageOptions());
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
LvAdapter
package adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import baseBean.Results;
import utils.ImageLoaderUtil;
import wangxuewei.bwie.com.week3.R;
/**
* Created by jim on 2017/10/21.
*/
public class LvAdapter extends BaseAdapter {
private List<Results.DataBean> list;
private Context context;
public LvAdapter(List<Results.DataBean> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(context, R.layout.lv_item, null);
holder = new ViewHolder();
holder.imageView = (ImageView) convertView.findViewById(R.id.item_img);
holder.textView = (TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(list.get(position).getNews_title());
ImageLoader.getInstance().displayImage(list.get(position).getPic_url(), holder.imageView, ImageLoaderUtil.getImageOptions());
return convertView;
}
class ViewHolder {
ImageView imageView;
TextView textView;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wangxuewei.bwie.com.week3">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
rb_select.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/holo_red_dark" android:state_checked="true" />
<item android:drawable="@android:color/holo_blue_dark" android:state_checked="false" />
</selector>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="wangxuewei.bwie.com.week3.MainActivity">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fr_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"></FrameLayout>
<RadioGroup
android:id="@+id/rg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_shouye"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rb_select"
android:button="@null"
android:checked="true"
android:gravity="center"
android:text="首页" />
<RadioButton
android:id="@+id/rb_faxian"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rb_select"
android:button="@null"
android:gravity="center"
android:text="发现" />
<RadioButton
android:id="@+id/rb_xiazai"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rb_select"
android:button="@null"
android:gravity="center"
android:text="下载" />
<RadioButton
android:id="@+id/rb_wode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rb_select"
android:button="@null"
android:gravity="center"
android:text="我的" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="钱包" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="行程记录" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="好友邀请" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
fr_others.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/text_others"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaa"
android:textSize="30dp" />
</LinearLayout>
fr_shouye.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorPrimaryDark"
app:tabTextColor="@color/colorPrimary" />
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v4.view.ViewPager>
</LinearLayout>
lv_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/item_img"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp" />
<TextView
android:id="@+id/item_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:textSize="20dp" />
</LinearLayout>
vp_others.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_vpother"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaa"
android:textSize="30dp" />
</LinearLayout>
vp_tuijian.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/vp_img"
android:layout_width="match_parent"
android:layout_height="200dp"></android.support.v4.view.ViewPager>
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/ptr_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
ptr:ptrAnimationStyle="flip"
ptr:ptrDrawable="@drawable/default_ptr_flip"
ptr:ptrHeaderBackground="#383838"
ptr:ptrHeaderTextColor="#FFFFFF"></com.handmark.pulltorefresh.library.PullToRefreshListView>
</LinearLayout>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。