Last active
August 29, 2015 14:21
-
-
Save li9ht/bace1d2b8a2656460bac to your computer and use it in GitHub Desktop.
android fragment listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class activitySecunder extends ActionBarActivity { | |
OnMukaUpdateListener onMukaUpdateListener; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_activity_secunder); | |
activitySecunderFragment firstFragment = new activitySecunderFragment(); | |
getSupportFragmentManager().beginTransaction() | |
.add(R.id.fragmentContainer,firstFragment) | |
.commit(); | |
onMukaUpdateListener = (OnMukaUpdateListener) firstFragment; | |
Button btn = (Button) findViewById(R.id.btn); | |
btn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
onMukaUpdateListener.onMukaUpdate("hi"); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class activitySecunderFragment extends Fragment implements OnMukaUpdateListener { | |
TextView tv2; | |
public activitySecunderFragment(){ | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.fragment_activity_secunder, container, false); | |
} | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState) { | |
tv2 = (TextView)view.findViewById(R.id.tv2); | |
super.onViewCreated(view, savedInstanceState); | |
} | |
@Override | |
public void onMukaUpdate(String text) { | |
tv2.setText(text); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface OnMukaUpdateListener { | |
public void onMukaUpdate(String text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment