I'm just learning about fragments. I followed an answer of creating an interface from a fragment to pass data back to my activity based on a button click and it works perfectly.
I can't figure out though how to have my fragment listen for a specific change in my activity after everything has been created, just like how my activity does it.
Basically I have a button in my activity and another button in my fragment. When I click on the button in my activity, I'd like to send some data over so that my fragment knows to change the text of my fragment button.
Here's my current fragment
public void onClickBtn1(View v) {
passData("abc");
}
public interface OnDataPass {
void onDataPass(String data);
}
OnDataPass dataPasser;
@Override
public void onAttach(Context a) {
super.onAttach(a);
dataPasser = (OnDataPass) a;
}
public void passData(String data) {
dataPasser.onDataPass(data);
}
and then this in my activity
@Override
public void onDataPass(String data) {
//do something with data
}
I'd like to somehow get this exact same thing but flip flopped. Any suggestions? Thanks!