listview多条目 GridView TabLayout pullToRefresh radioGroup +fragment



//做题前记得导包和导依赖

desing   ImageLoader   Gson   libaray


//mian方法

public class MainActivity extends AppCompatActivity {

    private RadioGroup rg;
    private ImageView img;
    private ListView lv;
    private DrawerLayout draw;
    private RelativeLayout rel;
    private List<String> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        draw= (DrawerLayout) findViewById(R.id.draw);
        rel= (RelativeLayout) findViewById(R.id.rel);
        rg= (RadioGroup) findViewById(R.id.rg);
        img= (ImageView) findViewById(R.id.img);
        lv= (ListView) findViewById(R.id.lv);
        list.add("个人设置");
        list.add("缓存");
        list.add("夜间模式");
        list.add("配置");
        addfragment(new Fristpage());
        ArrayAdapter adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                draw.closeDrawer(rel);
            }
        });
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId){
                    case R.id.rb_1: addfragment(new Fristpage());
                        break;
                    case R.id.rb_2:addfragment(new Fenleipage());
                        break;
                    case R.id.rb_3:addfragment(new Findpage());
                        break;
                    case R.id.rb_4:addfragment(new Buypage());
                        break;
                    case R.id.rb_5:addfragment(new Minepage());
                        break;
                }
            }
        });
    }
    public void addfragment(Fragment f){
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frag,f).commit();
    }
}


//工具类

public class ImageLoaderUtils {
    /**
     * ImageLoader的配置
     * @param context
     */
    public static void initConfig(Context context) {
        //配置
//        File cacheFile=context.getExternalCacheDir();
        File cacheFile= new File(Environment.getExternalStorageDirectory()+"/"+"imgages");

        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)//设置图片格式
                .displayer(new RoundedBitmapDisplayer(20))//设置圆角
                .build();

        return optionsoptions;

    }

}



//工具类

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 (MalformedURLException e) {
            e.printStackTrace();
        }catch (IOException 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);
    }
}


//工具类

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 "";
    }
}


//工具类

public class ImageUtil {
    public static void setListViewHeightBasedOnChildren(AbsListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            // pre-condition
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i,null , listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + ((listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }
}


//调用工具包

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ImageLoaderUtils.initConfig(this);
    }
}


//适配器

public class MyBaseAdapter extends BaseAdapter {
    private List<Resutl.DataBean> list;
    private Context context;

    public MyBaseAdapter(List<Resutl.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.item,null);
            holder=new ViewHolder();
            holder.img= (ImageView) convertView.findViewById(R.id.img);
            holder.tv= (TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().displayImage(list.get(position).getPic_url(), holder.img, ImageLoaderUtils.getImageOptions());
        holder.tv.setText(list.get(position).getNews_title());
        return convertView;
    }
    class ViewHolder{
        ImageView img;
        TextView tv;
    }
}

//适配器
public class MyJXAdapter extends BaseAdapter {
    private List<Resutl.DataBean> list;
    private Context context;

    private  final int TYPE_MEN=0;
    private  final int TYPE_WOMEN=1;

    public MyJXAdapter(List<Resutl.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getItemViewType(int position) {
        /*if(list.get(position).getPic_url()==null||list.get(position).getPic_url().equals("")){
            return  TYPE_MEN;
        }else{
            return TYPE_WOMEN;
        }*/
        if(position%2==0){
            return  TYPE_MEN;
        }else{
            return TYPE_WOMEN;
        }
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @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) {

        int type=getItemViewType(position);
        switch (type){
            case TYPE_MEN:
                ViewHolderMan holderMan;
                if(convertView==null){
                    convertView=View.inflate(context, R.layout.page1,null);
                    holderMan=new ViewHolderMan();

                    holderMan.tv2=(TextView) convertView.findViewById(R.id.tv2);
                    convertView.setTag(holderMan);

                }else{
                    holderMan=(ViewHolderMan) convertView.getTag();
                }

                holderMan.tv2.setText(list.get(position).getNews_title());
                return  convertView;


            case TYPE_WOMEN:

                ViewHolderWomen holderWomenMan;
                if(convertView==null){
                    convertView=View.inflate(context,R.layout.page2,null);
                    holderWomenMan=new ViewHolderWomen();

                    holderWomenMan.tv3=(TextView) convertView.findViewById(R.id.tv3);
                    holderWomenMan.img3=(ImageView) convertView.findViewById(R.id.img3);

                    convertView.setTag(holderWomenMan);

                }else{
                    holderWomenMan=(ViewHolderWomen) convertView.getTag();
                }

                holderWomenMan.tv3.setText(list.get(position).getNews_title());
                ImageLoader.getInstance().displayImage(list.get(position).getPic_url(), holderWomenMan.img3,ImageLoaderUtils.getImageOptions());

                return  convertView;

        }
        return null;
    }
    class ViewHolderMan{
        TextView tv2;
        ImageView img2;
    }

    class ViewHolderWomen{
        TextView tv3;
        ImageView img3;
    }
}


//fragment包下的fragment

public class Buypage extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.buycar,null);
        return  v;
    }
}


//fragment包下的fragment

public class Fenleipage extends Fragment {
    private ListView lv;
    private GridView gv;
    private List<String> list=new ArrayList<>();
    private List<Resutl.DataBean> data;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fenlei,null);
        lv= (ListView) v.findViewById(R.id.lv);
        gv= (GridView) v.findViewById(R.id.gv);
        list.add("美妆个护");
        list.add("钟表珠宝");
        list.add("手机数码");
        list.add("电脑办公");
        list.add("家用电器");
        list.add("食品生鲜");
        list.add("酒品饮料");
        list.add("母婴童装");

        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,list);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MyTask task=new MyTask(new MyTask.Icallbacks() {
                    @Override
                    public void updateUiByjson(String jsonstr) {
                        Gson gson=new Gson();
                        Resutl user = gson.fromJson(jsonstr, Resutl.class);
                        data = user.getData();
                        Mygvadapter ad=new Mygvadapter();
                        gv.setAdapter(ad);
                    }
                });
                task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+position);
            }
        });
        return  v;
    }
    class Mygvadapter extends BaseAdapter{

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.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(getActivity(),R.layout.item,null);
                holder=new ViewHolder();
                holder.img= (ImageView) convertView.findViewById(R.id.img);
                holder.tv= (TextView) convertView.findViewById(R.id.tv);
                convertView.setTag(holder);
            }else{
                holder= (ViewHolder) convertView.getTag();
            }
            ImageLoader.getInstance().displayImage(data.get(position).getPic_url(), holder.img, ImageLoaderUtils.getImageOptions());
            holder.tv.setText(data.get(position).getNews_title());
            return convertView;
        }
        class ViewHolder{
            ImageView img;
            TextView tv;
        }
    }
}


//fragment包下的fragment

public class Findpage extends Fragment {
    private TabLayout tab;
    private ViewPager vp;
    private String[] tabs=new String[]{"精选","英伦风","直播","订购","视频购","问答"};
    private Fragment[] f=new Fragment[6];
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.find,null);
        tab= (TabLayout) v.findViewById(R.id.tab);
        vp= (ViewPager) v.findViewById(R.id.vp);
        f[0]=new Jingxuan();
        f[1]=new Yinglun();
        f[2]=new Zhibo();
        f[3]=new Dingyue();
        f[4]=new Shipin();
        f[5]=new Wenda();

        vp.setOffscreenPageLimit(tabs.length);
        MyFragadapter adapter=new MyFragadapter(getChildFragmentManager());
        vp.setAdapter(adapter);
        tab.setupWithViewPager(vp);

        return  v;
    }
    class MyFragadapter extends FragmentPagerAdapter {


        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }

        public MyFragadapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return f[position];
        }

        @Override
        public int getCount() {
            return tabs.length;
        }
    }
}


//fragment包下的fragment


public class Fristpage extends Fragment {
    private MyBaseAdapter adap;
    private PullToRefreshScrollView pull;
    private GridView grid;
    private ImageView img;
    int i = 0;
    int index = 1;
    private List<Resutl.DataBean> data = new ArrayList<>();
    private List<Resutl.DataBean> listss = new ArrayList<>();
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            ImageLoader.getInstance().displayImage(data.get(i % data.size()).getPic_url(), img,ImageLoaderUtils.getImageOptions());
            i++;
            handler.sendEmptyMessageDelayed(0, 1000);
        }
    };

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fristpage, null);
        pull = (PullToRefreshScrollView) v.findViewById(R.id.pull);
        grid = (GridView) v.findViewById(R.id.grid);
        img = (ImageView) v.findViewById(R.id.img);
        MyTask task = new MyTask(new MyTask.Icallbacks() {

            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson = new Gson();
                Resutl u = gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();
                handler.sendEmptyMessageDelayed(0, 1000);
            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/1");

        initLv();
        initData();
        return v;
    }
    public void setAdapters(){
        if(adap==null){
            adap=new MyBaseAdapter(listss,getActivity());
            grid.setAdapter(adap);

        }else{
            adap.notifyDataSetChanged();
        }

    }
    public void initData(){
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();
                listss.addAll(data);
                setAdapters();
                ImageUtil. setListViewHeightBasedOnChildren(grid);
            }

        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/1");
    }
    public void addtoTop(){

        index=1;
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();

                listss.addAll(0,data);

                //刷新适配器
                setAdapters();
            }

        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);





    }

    public void addtoBottom(){
        index++;
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();

                listss.addAll(data);

                setAdapters();
            }

        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);



    }
    public void initLv(){
        //设置刷新模式 ,both代表支持上拉和下拉,pull_from_end代表上拉,pull_from_start代表下拉
        pull.setMode(PullToRefreshBase.Mode.BOTH);


/*这里通过getLoadingLayoutProxy 方法来指定上拉和下拉时显示的状态的区别,第一个true 代表下来状态 ,第二个true 代表上拉的状态
如果想区分上拉和下拉状态的不同,可以分别设置*/

        ILoadingLayout startLabels = pull.getLoadingLayoutProxy(true, false);
        startLabels.setPullLabel("下拉刷新");
        startLabels.setRefreshingLabel("正在拉");
        startLabels.setReleaseLabel("放开刷新");


        ILoadingLayout endLabels = pull.getLoadingLayoutProxy(false, true);
        endLabels.setPullLabel("上拉刷新");
        endLabels.setRefreshingLabel("正在载入...");
        endLabels.setReleaseLabel("放开刷新...");


/*如果Mode设置成Mode.BOTH,需要设置刷新Listener为OnRefreshListener2,并实现onPullDownToRefresh()、onPullUpToRefresh()两个方法。
  如果Mode设置成Mode.PULL_FROM_START或Mode.PULL_FROM_END,需要设置刷新Listener为OnRefreshListener,同时实现onRefresh()方法。
  当然也可以设置为OnRefreshListener2,但是Mode.PULL_FROM_START的时候只调用onPullDownToRefresh()方法,Mode.PULL_FROM_END的时候只调用onPullUpToRefresh()方法.

  加载数据完成后 必须 调用下 onRefreshComplete() 完成关闭 header,footer视图
*/

        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {//下拉刷新的回调
                //下拉刷新的数据,显示在listview列表的最上面
//                ImageUtil. setListViewHeightBasedOnChildren(grid);
                addtoTop();
                ImageUtil. setListViewHeightBasedOnChildren(grid);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();


                    }
                },1000);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {//上拉加载的回调
                //加载更多的数据,添加到集合列表的最后面
                addtoBottom();
                ImageUtil. setListViewHeightBasedOnChildren(grid);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();

                    }
                },1000);
            }
        });

    }

//fragment包下的fragment

public class Minepage extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.mine,null);
        return  v;
    }
}

//twofragment包下的fragment

public class Dingyue extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_yy, null);
        TextView tv = inflate.findViewById(R.id.tv);
        tv.setText("界面1");
        return inflate;
    }
} 



//twofragment包下的fragment

public class Jingxuan extends Fragment {
    private PullToRefreshListView pull;
    private Handler handler=new Handler();
    private List<Resutl.DataBean> data;
    private List<Resutl.DataBean> listss=new ArrayList<>();
    private MyJXAdapter adap;
    int index;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.jingxuan,null);
        pull= (PullToRefreshListView) v.findViewById(R.id.pull);

        initLv();
        initData();
        return v;
    }

    public void setAdapters(){
        if(adap==null){
            adap=new MyJXAdapter(listss,getActivity());
            pull.setAdapter(adap);

        }else{
            adap.notifyDataSetChanged();
        }

    }
    public void initData(){
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();
                listss.addAll(data);

                setAdapters();
            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/1");
    }
    public void addtoTop(){

        index=1;
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();

                listss.addAll(0,data);
                setAdapters();

            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);

    }
    public void addtoBottom(){
        index++;
        MyTask task=new MyTask(new MyTask.Icallbacks() {
            @Override
            public void updateUiByjson(String jsonstr) {
                Gson gson=new Gson();
                Resutl u=gson.fromJson(jsonstr, Resutl.class);
                data = u.getData();

                listss.addAll(data);
                setAdapters();
            }

        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);

    }
    public void initLv(){
        //设置刷新模式 ,both代表支持上拉和下拉,pull_from_end代表上拉,pull_from_start代表下拉
        pull.setMode(PullToRefreshBase.Mode.BOTH);

/*这里通过getLoadingLayoutProxy 方法来指定上拉和下拉时显示的状态的区别,第一个true 代表下来状态 ,第二个true 代表上拉的状态
如果想区分上拉和下拉状态的不同,可以分别设置*/

        ILoadingLayout startLabels = pull.getLoadingLayoutProxy(true, false);
        startLabels.setPullLabel("下拉刷新");
        startLabels.setRefreshingLabel("正在拉");
        startLabels.setReleaseLabel("放开刷新");


        ILoadingLayout endLabels = pull.getLoadingLayoutProxy(false, true);
        endLabels.setPullLabel("上拉刷新");
        endLabels.setRefreshingLabel("正在载入...");
        endLabels.setReleaseLabel("放开刷新...");


/*如果Mode设置成Mode.BOTH,需要设置刷新Listener为OnRefreshListener2,并实现onPullDownToRefresh()、onPullUpToRefresh()两个方法。
  如果Mode设置成Mode.PULL_FROM_START或Mode.PULL_FROM_END,需要设置刷新Listener为OnRefreshListener,同时实现onRefresh()方法。
  当然也可以设置为OnRefreshListener2,但是Mode.PULL_FROM_START的时候只调用onPullDownToRefresh()方法,Mode.PULL_FROM_END的时候只调用onPullUpToRefresh()方法.

  加载数据完成后 必须 调用下 onRefreshComplete() 完成关闭 header,footer视图
*/
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {//下拉刷新的回调
                //下拉刷新的数据,显示在listview列表的最上面
                addtoTop();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();
                    }
                },1000);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {//上拉加载的回调
                //加载更多的数据,添加到集合列表的最后面
                addtoBottom();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();

                    }
                },1000);
            }
        });
    }
}



//twofragment包下的fragment

public class Shipin extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_yy, null);
        TextView tv = inflate.findViewById(R.id.tv);
        tv.setText("界面2");
        return inflate;
    }
}


//twofragment包下的fragment

public class Wenda extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_yy, null);
        TextView tv = inflate.findViewById(R.id.tv);
        tv.setText("界面3");
        return inflate;
    }
}


//twofragment包下的fragment

public class Yinglun extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_yy, null);
        TextView tv = inflate.findViewById(R.id.tv);
        tv.setText("界面4");
        return inflate;
    }
}


//twofragment包下的fragment

public class Zhibo extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.layout_yy, null);
        TextView tv = inflate.findViewById(R.id.tv);
        tv.setText("界面5");
        return inflate;
    }
}

//Bean包下的数据

public class Resutl {
    /**
     * 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;
        }
    }
}


//radioGroup点击设置颜色

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_checked="true" android:drawable="@android:color/holo_red_dark"></item>
  <item android:drawable="@android:color/white"></item>
</selector>



//activity-main

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/draw"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.example.yuekaomoniti.activity.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <RadioGroup
            android:id="@+id/rg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">
            <RadioButton
                android:id="@+id/rb_1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="首页"
                android:padding="3dp"
                android:button="@null"
                android:textSize="25dp"
                android:checked="true"
                android:background="@drawable/select"/>
            <RadioButton
                android:id="@+id/rb_2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="分类"
                android:button="@null"
                android:padding="3dp"
                android:textSize="25dp"
                android:background="@drawable/select"/>
            <RadioButton
                android:id="@+id/rb_3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="发现"
                android:padding="3dp"
                android:button="@null"
                android:textSize="25dp"
                android:background="@drawable/select"/>
            <RadioButton
                android:id="@+id/rb_4"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="购物车"
                android:padding="3dp"
                android:button="@null"
                android:textSize="25dp"
                android:background="@drawable/select"/>
            <RadioButton
                android:id="@+id/rb_5"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="我的"
                android:padding="3dp"
                android:button="@null"
                android:textSize="25dp"
                android:background="@drawable/select"/>
        </RadioGroup>
        <FrameLayout
            android:id="@+id/frag"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/rg"></FrameLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rel"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffff00">
        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ac"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="15dp"

            />
        <ListView
            android:id="@+id/lv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/img"></ListView>
       <!-- <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="320dp"
            android:layout_marginLeft="50dp"
            android:text="个人设置"
            android:textColor="#f00"
            android:id="@+id/ge"
            android:textSize="22dp"
            />
        <TextView
            android:id="@+id/huan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="缓存"
            android:layout_marginTop="380dp"
            android:layout_marginLeft="50dp"
            android:textColor="#f00"
            android:textSize="22dp"
            />
        <TextView
            android:id="@+id/ye"
            android:textColor="#f00"
            android:layout_marginTop="460dp"
            android:layout_marginLeft="50dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="夜间模式"
            android:textSize="22dp"
            />-->
    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>



//buycar

<?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:background="#55DF82"
    >

</LinearLayout>


//fenlei

<?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:background="#D4F5FF"
    android:orientation="horizontal"
    >
    <ListView
        android:id="@+id/lv"
        android:layout_width="120dp"
        android:layout_height="match_parent"></ListView>

    <GridView
        android:id="@+id/gv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"></GridView>

</LinearLayout>


//find

<?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:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="center"
        app:tabIndicatorColor="@color/colorAccent"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/colorPrimaryDark"
        app:tabTextColor="@color/colorPrimary"
        android:id="@+id/tab"
        ></android.support.design.widget.TabLayout>

    <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>


//fristpage

<?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"
    xmlns:ptr="http://schemas.android.com/apk/res-auto">

    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        android:id="@+id/pull"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrDrawable="@drawable/default_ptr_flip"
        ptr:ptrHeaderBackground="#383838"
        ptr:ptrHeaderTextColor="#FFFFFF">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/img"
                android:layout_width="match_parent"
                android:layout_height="250dp" />
            <GridView
                android:id="@+id/grid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:numColumns="2"></GridView>
        </LinearLayout>
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>



</LinearLayout>


//item

<?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:orientation="vertical"
    >

    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="100dp" />
    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="100dp" />


</LinearLayout>


//jingxuan

<?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"
    xmlns:ptr="http://schemas.android.com/apk/res-auto">

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/pull"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrDrawable="@drawable/default_ptr_flip"
        ptr:ptrHeaderBackground="#383838"
        ptr:ptrHeaderTextColor="#FFFFFF"></com.handmark.pulltorefresh.library.PullToRefreshListView>


</LinearLayout>


layout_yy

<?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="界面"
        android:id="@+id/tv"
        />

</LinearLayout>


//mine

<?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">

</LinearLayout>


//page1

<?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:orientation="vertical"
    >

    <TextView
        android:id="@+id/tv2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>


//page2

<?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:orientation="vertical"
    >

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <ImageView
        android:id="@+id/img3"
        android:layout_width="80dp"
        android:layout_height="80dp" />

</LinearLayout>


//要加的权限

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
android:name=".activity.MyApplication"

 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值