android callback interface


public class MyButton {
    public interface MyListener {
      // you can define any parameter as per your requirement
      public void callback(View view, String result);
   }
    MyListener ml;

    // constructor
    MyButton(MyListener ml) {
        this.ml = ml;
    }

    public void MyLogicToIntimateOthere() {
        ml.callback(this, "success");
    }
}
public class MyActivity extends Activity implements MyListener {
   @override        
   public void onCreate(){
        MyButton m = new MyButton(this);
   }

    // method invoke when mybutton will click
    @override
    public void callback(View view, String result) {   
      System.out.println(result);
    }
}

Leave a Reply