1
在我的项目中,我使用的ViewPager的一个操作栏,并有三个选项卡片段 还有一个第四个fragemnt,当我点击第一个片段中的按钮,第四个碎片,现在在这里我面临的问题,当我点击第四个碎片的列表项时,我需要将列表数据传递给第一个标签(第一个碎片)并显示它。 我使用的套件,下面Android:在viewpager之间传递片段之间的数据
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();
}
});
}
在我的第四个FRAG发送数据,而在我的第一个FRAG我打电话束如下
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);
}}
任何帮助表示赞赏。
片段片段通信可以通过相关的活动 – Raghunandan
@Raghunandan嗨,你可以给一个工作示例的行动,行动我在做什么? – teekib
嗨检查检查这个http://stackoverflow.com/questions/18492791/how-to-pass-a-string-between-fragments-in-a-viewpager – Mohan