我已使用this教程实现了可交换的标签视图。
我想将一个整数值从Fragment传递给FragmentActivity。怎么做?
我的fragment.java
:
public PastaFragment(FragmentManager fm, int hot_number) {
super();
this.hot_number = hot_number;
}
内部片段onCreate:
mCartList = ShoppingCartHelper.getCartList();
// Make sure to clear the selections
for (int i = 0; i < mCartList.size(); i++) {
mCartList.get(i).selected = false;
hot_number = mCartList.size();
System.out.println("hot_number11 = " + hot_number);
}
Fragment Pasfragment = new PastaFragment(getFragmentManager(), hot_number);
Bundle bundle = new Bundle();
bundle.putLong("hot_number", hot_number);
Pasfragment.setArguments(bundle);
内部activityfragment.java
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
hot_number = getIntent().getIntExtra("hot_number", hot_number);
内部TabsPagerAdapter.java
:
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
FragmentManager getFragmentManager = null;
return new PastaFragment(getFragmentManager, index);
}
return null;
}
答案 0 :(得分:0)
尝试这种方式:
Intent intent = new Intent(getActivity(), YourFragmentActivity.class);
intent.putExtra("YourInteger", 1);
getActivity().startActivity(intent);