In my project i am using a Actionbar with viewpager and has three tabs which are fragments there is one more fourth fragemnt,when i click on the button in first fragment i am replacing it with fourth frag, now here where i am facing issue when i click on the list item of fourth frag i need to pass the list data to the first tab (first fragment) and display it. I am using Bundle for sending data as in my fourth frag below
public class PlaceSearchFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.autosearchactivity, container, false);
return rootView;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parentView, View view, int position,
long arg3) {
int product =lv.getId();
Bundle bundle = new Bundle();
bundle.putInt("y", product); //any string to be sent
System.out.println("Bundle loaded "+product);
Fragment newFragment = new GetRideFragment();
newFragment.setArguments(bundle);
Fragment productDetailFragment = new GetRideFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.remove(PlaceSearchFragment.this);
transaction.replace(R.id.replaceautosearch, productDetailFragment,"yourfragment").commit();
}
});
}
And in my first frag i am calling bundle as below
public class Myplace extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.autosearchactivity, container, false);
return rootView;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if ( b != null ){
b = getArguments();
int s = b.getInt("y");
System.out.println("printinf bundle data==>"+s);
getfrom.setText(""+s);
}}
Any help is appreciated.