黑马程序员——关于接口

public class AsyncImageLoader {
 
 private static final String TAG = "AsyncImageLoader";
 //第一一个map集合,添加软引用。
 private Map<String, SoftReference<Drawable>> imageCache=
   new HashMap<String, SoftReference<Drawable>>();
 
 public Drawable loadDrawable(final String imageUrl,final ImageCallback callback){
  if(imageCache.containsKey(imageUrl)){
   //要是图片的网页地址存在的话就直接返回
   SoftReference<Drawable> softReference=imageCache.get(imageUrl);
   if(softReference.get()!=null){
    return softReference.get();
   }
  }
  //handler时间处理
  final Handler handler=new Handler(){
   @Override
   public void handleMessage(Message msg) {
    callback.imageLoaded((Drawable) msg.obj, imageUrl);
   }
  };
  //开启一个线程。
  new Thread(){
   public void run() {
    Drawable drawable=loadImageFromUrl(imageUrl);
    imageCache.put(imageUrl, new SoftReference<Drawable>(drawable));
    handler.sendMessage(handler.obtainMessage(0,drawable));
   };
  }.start();
  return null;
 }
 
 
 protected Drawable loadImageFromUrl(String imageUrl) {
  try {
   //直接返回图片
   return Drawable.createFromStream(new URL(imageUrl).openStream(),"src");
  } catch (Exception e) {
  }
  return null;//返回空
 }
 //第一一个接口
 public interface ImageCallback{
  public void imageLoaded(Drawable imageDrawable,String imageUrl);
 }
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
关于接口的一些特点:
接口的变量一般都为常量。
接口的方法没方法是实现方式,不能被实例化。
接口没构造方法。
接口不能实现接口,但是接口可以继承接口
接口的方法可以通过类来实现。
 
 
 
下面是我写的小介绍案例
 
interface Animal{
    void eatfood();
    void running();
}
 
class Dog implements Animal{
    public void eatfood(){
       System.out.println("开始吃骨头啦!");
    }
    public void running(){
       System.out.println("小狗跑来跑去!");
    }
}
 
class Cat implements Animal{
    public void eatfood(){
       System.out.println("小猫吃鱼!");
    }
    public void running(){
       System.out.println("小猫树上跑!");
    }
}

 
public class InterTest{
         public static void main(String[] args)
         {
                   Animal p=new Animal();
                   p.eatfood();
                   p.running();
                   p=new Dog();
                   p.eatfood();
                   p.running();
                   p=new Cat();
                   p.eatfood();
                   p.running();
         }
}
 
<span style="font-size:18px;"><span style="color:#333333;background: white;"></span></span> 
 
<span style="color:#909090;">------- </span><a target=_blank style="color: rgb(126, 93, 58);" href="http://www.itheima.com/" target="blank" rel="nofollow">android培训</a><span style="color:#909090;">、</span><a target=_blank style="color: rgb(126, 93, 58);" href="http://www.itheima.com/" target="blank" rel="nofollow">java培训</a><span style="color:#909090;">、</span><a target=_blank style="color: rgb(126, 93, 58);" href="http://www.itheima.com/" target="blank" rel="nofollow">IOS培训</a><span style="color:#909090;">、</span><a target=_blank style="color: rgb(126, 93, 58);" href="http://www.itheima.com/" target="blank" rel="nofollow">.Net培训</a><span style="color:#909090;">期待与您交流! ----------</span>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值