网络请求(viewPager,Fragment,ListView)

数据接口地址:(校园内部地址,不能使用网络流量访问)
三张向导图片的接口文件:
http://172.17.29.120/localuser/ljy/ndhx/pic.json

栏目导航接口文件:
http://172.17.29.120/localuser/ljy/ndhx/nav.json

关于我们接口文件:
http://172.17.29.120/localuser/ljy/ndhx/about.json

培训动态接口文件:
http://172.17.29.120/localuser/ljy/ndhx/peixundongtai.json

 案列要求:
  1. 向导图片的相关json文件的解析以及展示
    1.1 解析结果代码正确
    1.2 viewpager代码正确
    1.3前三张导航图片滑动后,最后一张上面显示一个按钮,点击按钮后跳转到主页面
    1.4第二次进入后,不在显示向导图片,直接跳转到主页面。
  2. 访问网络,请求nav.json数据
    2.1: 使用Asynctask解析数据
    2.2:能解析到数据
    2.3:解析到数据之后存储到集合

  3. 访问网络,请求aboutus.json数据
    3.1: 使用Asynctask解析数据
    3.2:能解析到数据
    3.3:解析到数据之后存储到集合

  4. 访问网络,请求peixundongtai.json数据
    4.1: 使用Asynctask解析数据
    4.2:能解析到数据
    4.3:解析到数据之后存储到集合

  5. 自定义Adapter+listview 展示数据
    5.1:自定义adapter
    5.2:listview加载数据
    5.3:使用listview优化

  6. 第一个页面效果
    6.1:上面的三个导航项
    6.2:点击每个导航切换到不同的fragment
    6.3:下面listview展示效果


主界面布局
<RelativeLayout 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"
    >

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_main_viewpager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/main_button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="38dp"
        android:visibility="gone"
        android:text="欢迎进入系统" />

</RelativeLayout>
第二个界面布局
<LinearLayout 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"
    android:orientation="vertical"
     >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <TextView 
            android:id="@+id/tv_two_textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="15dp"
            android:padding="10dp"
            android:text="关于恒博"
            />
        <TextView 
            android:id="@+id/tv_two_textview2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="15dp"
            android:padding="10dp"
            android:text="关于恒博"
            />
        <TextView 
            android:id="@+id/tv_two_textview3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="15dp"
            android:padding="10dp"
            android:text="公司位置"
            />


    </LinearLayout>
    <RelativeLayout 
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        ></RelativeLayout>
</LinearLayout>
Fragment 界面布局
<?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" >


    <ListView 
        android:id="@+id/lv_main_listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ></ListView>
</LinearLayout>
LIstView 条目布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/other_imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="37dp"
        android:layout_marginTop="50dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/other_textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/other_imageView1"
        android:layout_alignParentRight="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/other_textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="24dp"
        android:layout_toRightOf="@+id/other_imageView1"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>
三个 bean包
package com.exam.bean;

public class Titles {

    public String classname;
}


----------
package com.exam.bean;

import java.util.List;

public class Hengbo {
    public List<Myinfo> info;

    public class Myinfo{
        public String picurl;
        public String title;
        public String uptime;   
    }
}


----------
package com.exam.bean;

public class Tupian {

    public String src;

    @Override
    public String toString() {
        return "Tupian [src=" + src + "]";
    }       
}
工具类
package com.exam.utile;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class MyUtile {  
    public static String getString(String path){

        try {
            URL url = new URL(path);
            HttpURLConnection openConnection=(HttpURLConnection) url.openConnection();
            openConnection.setConnectTimeout(5000);
            openConnection.setReadTimeout(5000);
            int responseCode = openConnection.getResponseCode();
            if (responseCode==200) {
                InputStream inputStream = openConnection.getInputStream();
                ByteArrayOutputStream arrayOutputStream=new ByteArrayOutputStream();
                byte[] b=new byte[1024];
                int len=0;
                while ((len=inputStream.read(b))!=-1) {
                    arrayOutputStream.write(b, 0, len);
                }
                return arrayOutputStream.toString("gbk");
            }


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
        return null;        
    }   
}


----------
package com.exam.imafeloader;
import com.example.zhangweixin1409r20160530.R;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration.Builder;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.content.Context;
import android.graphics.Bitmap;

public class ImageLoaderUtils {
    /**
     * 初始化ImageLoaderConfiguration 这个可以只做简单的初始化,此方法建议在
     * Application中进行初始化
     * 
     * @param context
     */

    public static void initConfiguration(Context context){

        Builder configuration = new ImageLoaderConfiguration.Builder(context);

        // --------------------------------------------------------------------
        // 本段代码,如果是测试使用时,可以不添加,不影响ImageLoader的正常使用
         configuration.memoryCacheExtraOptions(480, 800)
         // default = device screen dimensions
         // 缓存到磁盘中的图片宽高
         .diskCacheExtraOptions(480, 800, null)
         // .taskExecutor(null)
         // .taskExecutorForCachedImages()
         .threadPoolSize(3)
         // default 线程优先级
         .threadPriority(Thread.NORM_PRIORITY - 2)
         // default
         .tasksProcessingOrder(QueueProcessingType.FIFO)
         // // default设置在内存中缓存图像的多种尺寸
         // 加载同一URL图片时,imageView从小变大时,从内存缓存中加载
         .denyCacheImageMultipleSizesInMemory()
         // 超过设定的缓存大小时,内存缓存的清除机制
         .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
         // 内存的一个大小
         .memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13)
         // default 将图片信息缓存到该路径下
         // default 磁盘缓存的大小
         .diskCacheSize(50 * 1024 * 1024)
         // 磁盘缓存文件的个数
         .diskCacheFileCount(100)
         // 磁盘缓存的文件名的命名方式//一般使用默认值 (获取文件名称的hashcode然后转换成字符串)或MD5 new
         // Md5FileNameGenerator()源文件的名称同过md5加密后保存
         .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
         // 设置默认的图片加载
         // 使用默认的图片解析器
         .imageDecoder(new BaseImageDecoder(true)) // default
         .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) //
         .writeDebugLogs();

        // ---------------------------------------------------------------------
        ImageLoader.getInstance().init(configuration.build());
    }

    /**
     * 初始化DisplayImageOptions
     * @param context
     * @return
     */
    public static DisplayImageOptions initOptions(){

         DisplayImageOptions options = new DisplayImageOptions.Builder()
            // 设置图片在下载期间显示的图片
                    .showImageOnLoading(R.drawable.ic_launcher)
                    // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.drawable.ic_launcher)
                    // 设置下载的图片是否缓存在内存中
                    .cacheInMemory(true)
                    // 设置下载的图片是否缓存在SD卡中
                    .cacheOnDisc(true)
                    // --------------------------------------------------------------------
        // 如果您只想简单使用ImageLoader这块也可以不用配置
        // 是否考虑JPEG图像EXIF参数(旋转,翻转)
        .considerExifParams(true)
        // 设置图片以如何的编码方式显示
        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
        // 设置图片的解码类型//
        .bitmapConfig(Bitmap.Config.RGB_565)
        // 设置图片的解码配置
        // .decodingOptions(options)
        // .delayBeforeLoading(int delayInMillis)//int
        // delayInMillis为你设置的下载前的延迟时间
        // 设置图片加入缓存前,对bitmap进行设置
        // .preProcessor(BitmapProcessor preProcessor)
        // 设置图片在下载前是否重置,复位
        .resetViewBeforeLoading(true)
        // 是否设置为圆角,弧度为多少
        .displayer(new RoundedBitmapDisplayer(20))
        // 是否图片加载好后渐入的动画时间
        .displayer(new FadeInBitmapDisplayer(100))
        // 构建完成
        // -------------------------------------------------------------------

                    .build();
            return options;
    }   
}


----------
package com.exam.imafeloader;

import android.app.Application;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        ImageLoaderUtils.initConfiguration(getApplicationContext());


    }
}

 MainActivity 主界面

package com.exam;

import com.bwei.list.MyPagerAdapter;
import com.exam.bean.Tupian;
import com.exam.imafeloader.ImageLoaderUtils;
import com.exam.utile.MyUtile;
import com.example.zhangweixin1409r20160530.R;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    private DisplayImageOptions options;
    private ViewPager vp_main_viewpager;
    private String path = "http://172.17.29.120/localuser/ljy/ndhx/pic.json";
    private Button main_button1;
    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 找到控件
        vp_main_viewpager = (ViewPager) findViewById(R.id.vp_main_viewpager);
        main_button1 = (Button) findViewById(R.id.main_button1);
        options = ImageLoaderUtils.initOptions();
        // 二次登陆
        sharedPreferences = getSharedPreferences("config", MODE_PRIVATE);
        boolean boolean1 = sharedPreferences.getBoolean("flag", false);
        if (boolean1) {
            Intent intent = new Intent(MainActivity.this, TwoActivity.class);
            startActivity(intent);
        }
        // AsyncTask 异步线程
        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute(path);
        // 按钮点击监听
        // 欢迎页、跳
        main_button1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Editor edit = sharedPreferences.edit();
                edit.putBoolean("flag", true);
                edit.commit();
                Intent intent = new Intent(MainActivity.this, TwoActivity.class);
                startActivity(intent);
            }
        });

    }

    class MyAsyncTask extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            String string = MyUtile.getString(params[0]);

            return string;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Gson gson = new Gson();
            Tupian[] fromJson = gson.fromJson(result, Tupian[].class);
            for (int i = 0; i < fromJson.length; i++) {
                Log.i("MainActivity", fromJson[i].src);

            }

            MyPagerAdapter myPagerAdapter = new MyPagerAdapter(fromJson,
                    MainActivity.this, options);
            vp_main_viewpager.setAdapter(myPagerAdapter);
            getvpjianting(fromJson);
        }

    }

    public void getvpjianting(final Tupian[] fromJson) {
        // viewPager 监听
        vp_main_viewpager.setOnPageChangeListener(new OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // TODO Auto-generated method stub
                if (position == fromJson.length - 1) {
                    main_button1.setVisibility(View.VISIBLE);
                } else {
                    main_button1.setVisibility(View.GONE);
                }
            }

            @Override
            public void onPageScrolled(int position, float positionOffset,
                    int positionOffsetPixels) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int state) {
                // TODO Auto-generated method stub
            }
        });
    }
}
TwoActivity 第二个界面

package com.exam;

import com.exam.bean.Titles;
import com.exam.fragment.Fragment1;
import com.exam.fragment.Fragment2;
import com.exam.utile.MyUtile;
import com.example.zhangweixin1409r20160530.R;
import com.google.gson.Gson;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class TwoActivity extends FragmentActivity implements OnClickListener{

    private TextView tv_two_textview1;
    private TextView tv_two_textview2;
    private FragmentManager supportFragmentManager;
    private String path="http://172.17.29.120/localuser/ljy/ndhx/nav.json";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        tv_two_textview1 = (TextView) findViewById(R.id.tv_two_textview1);
        tv_two_textview2 = (TextView) findViewById(R.id.tv_two_textview2);
        tv_two_textview1.setOnClickListener(this);
        tv_two_textview2.setOnClickListener(this);

        tv_two_textview1.setTextColor(Color.BLUE);
         supportFragmentManager = getSupportFragmentManager();
         FragmentTransaction beginTransaction = supportFragmentManager.beginTransaction();
        beginTransaction.add(R.id.ll, new Fragment1(), "Fragment1");
        beginTransaction.commit();

        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute(path);

    }



    class MyAsyncTask extends AsyncTask<String, Void, String>{

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            String string = MyUtile.getString(params[0]);

            return string;
        }
        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Gson gson=new Gson();
            Titles[] fromJson = gson.fromJson(result, Titles[].class);
            tv_two_textview1.setText(fromJson[0].classname);
            tv_two_textview2.setText(fromJson[1].classname);
        }

    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.tv_two_textview1:
            tv_two_textview1.setTextColor(Color.BLUE);
            tv_two_textview2.setTextColor(Color.BLACK);

             FragmentTransaction beginTransaction = supportFragmentManager.beginTransaction();
                beginTransaction.replace(R.id.ll, new Fragment1(), "Fragment1");
                beginTransaction.commit();

            break;
        case R.id.tv_two_textview2:
            tv_two_textview2.setTextColor(Color.BLUE);
            tv_two_textview1.setTextColor(Color.BLACK);
             FragmentTransaction beginTransaction2 = supportFragmentManager.beginTransaction();
                beginTransaction2.replace(R.id.ll, new Fragment2(), "Fragment2");
                beginTransaction2.commit();
            break;

        default:
            break;
        }
    }
}
第一个 Fragment 界面

package com.exam.fragment;

import com.bwei.list.MyBaseAdapter;
import com.exam.bean.Hengbo;
import com.exam.imafeloader.ImageLoaderUtils;
import com.exam.utile.MyUtile;
import com.example.zhangweixin1409r20160530.R;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class Fragment1 extends Fragment {


    private ListView lv_main_listview;
    private String path="http://172.17.29.120/localuser/ljy/ndhx/about.json";
    private DisplayImageOptions options;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view=inflater.inflate(R.layout.fragment, container,false);
        lv_main_listview = (ListView) view.findViewById(R.id.lv_main_listview);

        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        options = ImageLoaderUtils.initOptions();
        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute(path);

    }

    class MyAsyncTask extends AsyncTask<String, Void, String>{

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            String string = MyUtile.getString(params[0]);

            return string;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Gson gson=new Gson();
            Hengbo fromJson = gson.fromJson(result, Hengbo.class);
            MyBaseAdapter myBaseAdapter = new MyBaseAdapter(fromJson.info, getActivity(), options);
            lv_main_listview.setAdapter(myBaseAdapter);

        }

    }

}


----------
第二个 Fragment 界面

package com.exam.fragment;

import com.bwei.list.MyBaseAdapter;
import com.exam.bean.Hengbo;
import com.exam.fragment.Fragment1.MyAsyncTask;
import com.exam.imafeloader.ImageLoaderUtils;
import com.exam.utile.MyUtile;
import com.example.zhangweixin1409r20160530.R;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class Fragment2 extends Fragment {

    private ListView lv_main_listview;
    private String path="http://172.17.29.120/localuser/ljy/ndhx/peixundongtai.json";
    private DisplayImageOptions options;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view=inflater.inflate(R.layout.fragment, container,false);
        lv_main_listview = (ListView) view.findViewById(R.id.lv_main_listview);

        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        options = ImageLoaderUtils.initOptions();
        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute(path);

    }

    class MyAsyncTask extends AsyncTask<String, Void, String>{

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            String string = MyUtile.getString(params[0]);

            return string;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Gson gson=new Gson();
            Hengbo fromJson = gson.fromJson(result, Hengbo.class);
            MyBaseAdapter myBaseAdapter = new MyBaseAdapter(fromJson.info, getActivity(), options);
            lv_main_listview.setAdapter(myBaseAdapter);     
        }       
    }       
}
适配器 :ListView和ViewPager

**ListView**

package com.bwei.list;

import java.util.List;

import com.exam.bean.Hengbo.Myinfo;
import com.example.zhangweixin1409r20160530.R;
import com.example.zhangweixin1409r20160530.R.layout;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyBaseAdapter extends BaseAdapter {

    private List<Myinfo> list;
    private Context context;
    private DisplayImageOptions options;

    public MyBaseAdapter(List<Myinfo> list, Context context,
            DisplayImageOptions options) {
        super();
        this.list = list;
        this.context = context;
        this.options = options;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View view=LayoutInflater.from(context).inflate(R.layout.other, null);
        ImageView imageView=(ImageView) view.findViewById(R.id.other_imageView1);
        TextView other_textView1=(TextView) view.findViewById(R.id.other_textView1);
        TextView other_textView2=(TextView) view.findViewById(R.id.other_textView2);
        other_textView1.setText(list.get(position).title);
        other_textView2.setText(list.get(position).uptime);

        ImageLoader.getInstance().displayImage(list.get(position).picurl,imageView, options);


        return view;
    }

}


----------
**ViewPager**

package com.bwei.list;

import com.exam.bean.Tupian;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class MyPagerAdapter extends PagerAdapter {

    private Tupian[] tupians;
    private  Context context;
    private DisplayImageOptions options;
    public MyPagerAdapter(Tupian[] tupians, Context context,
            DisplayImageOptions options) {
        super();
        this.tupians = tupians;
        this.context = context;
        this.options = options;
    }




    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return tupians.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        // TODO Auto-generated method stub
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // TODO Auto-generated method stub
        ImageView imageView = new ImageView(context);
        imageView.setScaleType(ScaleType.FIT_XY);
        ImageLoader.getInstance().displayImage("http://172.17.29.120/localuser/ljy/ndhx/"+tupians[position].src,imageView, options);
        container.addView(imageView);
        return imageView;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
//      super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}

案列,欢迎页效果图
案列,主页面效果图

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值