download: http://www.mediafire.com/file/pmk0jckln50sm78/MyListner1.zip
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements MyListener {
TextView tv_msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_msg =(TextView) findViewById(R.id.tv_msg);
MyButton mMyButton = new MyButton(this);
}
@Override
public void callback(MyButton view, String result) {
System.out.println(" MainActivity callback");
tv_msg.setText("MainActivity callback" + " result="+result);
}
}
-----------------------------------------------------------------------------------------
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
public class MyButton {
MyListener ml;
// constructor
MyButton(MyListener ml) {
this.ml = ml;
myLogicToIntimateOthere();
}
public void myLogicToIntimateOthere() {
ml.callback(this, "success");
}
}
-----------------------------------------------------------------------------------------
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
import android.view.View;
public interface MyListener {
// you can define any parameter as per your requirement
public void callback(MyButton view, String result);
}
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements MyListener {
TextView tv_msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_msg =(TextView) findViewById(R.id.tv_msg);
MyButton mMyButton = new MyButton(this);
}
@Override
public void callback(MyButton view, String result) {
System.out.println(" MainActivity callback");
tv_msg.setText("MainActivity callback" + " result="+result);
}
}
-----------------------------------------------------------------------------------------
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
public class MyButton {
MyListener ml;
// constructor
MyButton(MyListener ml) {
this.ml = ml;
myLogicToIntimateOthere();
}
public void myLogicToIntimateOthere() {
ml.callback(this, "success");
}
}
-----------------------------------------------------------------------------------------
package collapsingtoolbarlikewhatsapp.startingandroid.com.mylistner;
import android.view.View;
public interface MyListener {
// you can define any parameter as per your requirement
public void callback(MyButton view, String result);
}
No comments:
Post a Comment