一般的なフレームワークのデモ

3238 ワード

public class MyApplication extends Application { public void onCreate() { DisplayImageOptions defaultDisplayImageOptions=new DisplayImageOptions .Builder() .cacheInMemory(true) .cacheOnDisk(true).build();
 ImageLoaderConfiguration imageLoaderConfiguration=new ImageLoaderConfiguration.Builder(getApplicationContext())
    .defaultDisplayImageOptions(defaultDisplayImageOptions)
    .diskCacheSize(50 * 1024 * 1024)
    .memoryCache(new UsingFreqLimitedMemoryCache(5 * 1024 * 1024)).build();

 ImageLoader.getInstance().init(imageLoaderConfiguration);

};
}
//////////////////////////////////////////////// public class MainActivity extends Activity { private Button button1; private ListView listView; private ArrayList list; private DisplayImageOptions displayImageOptions; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.listView); displayImageOptions = new DisplayImageOptions.Builder() .showImageForEmptyUri(R.drawable.ic_launcher) .showImageOnFail(R.drawable.ic_launcher) .showImageOnLoading(R.drawable.ic_launcher) .cacheInMemory(true) .cacheOnDisc(true) .considerExifParams(true) .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .bitmapConfig(Bitmap.Config.RGB_565) .delayBeforeLoading(100) .resetViewBeforeLoading(true) .displayer(new FadeInBitmapDisplayer(100)).build();
}
public void getFile(View v){
    HttpUtils httpUtils=new HttpUtils();
    String path = "http://v.juhe.cn/weixin/query?key=0917c812f187b92e025c9b7c2d4e59b5&pno=2";
    httpUtils.send(HttpMethod.GET, path, new RequestCallBack<String>() {
        @Override
        public void onFailure(HttpException arg0, String arg1) {
            Toast.makeText(MainActivity.this, " !", 0).show();
        }
        @Override
        public void onSuccess(ResponseInfo<String> arg0) {
            String result = arg0.result;
            Gson gson=new Gson();
            News news = gson.fromJson(result, News.class);
            list = news.result.list;
            listView.setAdapter(new BaseAdapter() {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    ImageView imageView=new ImageView(MainActivity.this);
                    ImageLoader imageLoader=ImageLoader.getInstance();
                    imageLoader.displayImage(list.get(position).firstImg, imageView, displayImageOptions);
                    return imageView;
                }

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

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

        }
    });
}

} /////////////////////////////////////////////