I am working with a ViewPager and I have three fragments Fragment A, Fragment B and Fragment C in which Fragment A and Fragment B are to communicate Fragment C. I have implemented the communication logic but here's the thing: I cannot refresh/update the view of Fragment C when data is passed from Fragment B. Everything works fine when Fragment A and Fragment C are to communicate: the views are updated according to the data passed.
Fragment C here is a MediaPlayer ... It plays the media url communicated from Fragment B, but there is change in the layout. Can someone please tell me what's going on here. Here's what I have done till now:
Interface
public interface MediaInterface {
public void onPodCastClick(int position,
ArrayList<HashMap<String, String>> toPass);
}
In both the Fragment A and B
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
String title = data.get(position).get("Title").toString();
SM.setCurrentPlayedID(title);
popPass.onPodCastClick(position, data);
}
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
try{
popPass = (MediaInterface)getActivity();
} catch(ClassCastException e){
Log.i(tag, "Activity " + getActivity().getClass().getSimpleName()
+ " does not implement the MediaInterface");
e.printStackTrace();
}
}
where popPass is an instance of the MediaInterface.
In the MainActivity (where the ViewPager is implemented)
@Override
public void onPodCastClick(int position,
ArrayList<HashMap<String, String>> toPass) {
// TODO Auto-generated method stub
Bundle element = new Bundle();
element.putSerializable("toPass", toPass);
element.putInt("position", position);
Fragment toGo = new FragmentC();
toGo.setArguments(element);
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add(toGo, "FragmentC").commit();
pager.setCurrentItem(FRAGMENT_C);
}
In Fragment C
Bundle element = getActivity().getSupportFragmentManager()
.findFragmentByTag("FragmentC").getArguments();
where there are changes made in the views according to the elements in the Bundle.
Please do help me figure out what's happening and how do I refresh this fragment.
I also did see this from the android developers documentation ... but they did not mention a way to update the UI.