标签:imp app package 导致 r.java his sig 问题: rs.remove
1. 观察者模式
package com.example.jingbin.designpattern.observer.interfaces; /** * Created by jingbin on 2016/10/21. * 专题接口,所有的主题必须实现此接口 */ public interface Subject { /** * 注册一个观察者 */ public void registerObserver(Observer observer); /** * 移除一个观察者 */ public void removeObserver(Observer observer); /** * 通知所有观察者 */ public void notifyObservers(); }
package com.example.jingbin.designpattern.observer.classs; import com.example.jingbin.designpattern.observer.interfaces.Observer; import com.example.jingbin.designpattern.observer.interfaces.Subject; import java.util.ArrayList; /** * Created by jingbin on 2016/10/21. * 接下来3D服务号的实现类: */ public class ObjectFor3D implements Subject { private ArrayList<Observer> observers = new ArrayList<>(); /** * 3D 彩票的号码 */ private String msg; @Override public void registerObserver(Observer observer) { observers.add(observer); } @Override public void removeObserver(Observer observer) { int index = observers.indexOf(observer); if (index >= 0) { observers.remove(index); } } @Override public void notifyObservers() { for (Observer observer : observers) { observer.update(msg); } } /** * 主题更新信息 */ public void setMsg(String msg) { this.msg = msg; notifyObservers(); } }
package com.example.jingbin.designpattern.observer.interfaces; /** * Created by jingbin on 2016/10/21. * 所有观察者需要实现此接口 */ public interface Observer { public void update(String msg); }
package com.example.jingbin.designpattern.observer.classs; import android.util.Log; import com.example.jingbin.designpattern.observer.interfaces.Observer; import com.example.jingbin.designpattern.observer.interfaces.Subject; /** * Created by jingbin on 2016/10/21. * 模拟第一个使用者 */ public class ObserverUser1 implements Observer { public ObserverUser1(Subject subject) { subject.registerObserver(this); } @Override public void update(String msg) { Log.e("-----ObserverUser1 ", "得到 3D 号码:" + msg + ", 我要记下来。 "); // Toast.makeText(PatternApplication.getInstance(), "-----ObserverUser1 得到 3D 号码:" + msg, Toast.LENGTH_SHORT).show(); } }
package com.example.jingbin.designpattern.observer.classs; import android.util.Log; import com.example.jingbin.designpattern.observer.interfaces.Observer; import com.example.jingbin.designpattern.observer.interfaces.Subject; /** * Created by jingbin on 2016/10/21. * 模拟第二个使用者 */ public class ObserverUser2 implements Observer { public ObserverUser2(Subject subject) { subject.registerObserver(this); } @Override public void update(String msg) { Log.e("-----ObserverUser2 ", "得到 3D 号码:" + msg + ", 我要告诉舍友们。"); // Toast.makeText(PatternApplication.getInstance(), "-----ObserverUser2 得到 3D 号码:" + msg, Toast.LENGTH_SHORT).show(); } }
// 创建服务号 objectFor3D = new ObjectFor3D(); // 创建两个订阅者 observerUser1 = new ObserverUser1(objectFor3D); observerUser2 = new ObserverUser2(objectFor3D); // 两个观察者,发送两条信息 objectFor3D.setMsg("201610121 的3D号为:127"); objectFor3D.setMsg("20161022 的3D号为:000");
标签:imp app package 导致 r.java his sig 问题: rs.remove
原文地址:https://www.cnblogs.com/jlcs/p/9845083.html