我跟着谷歌教程,並沒有得到我的代碼中的任何錯誤,但由於某種原因,我的包中的數據似乎並沒有從我的主要活動發送到我的片段(我的應用程序只是不斷返回「0.00」)。請幫忙。從主活動發送包到片段
主要活動:
@Override
public void assignButtonBWHW1Clicked(String assignButtonBWHWClicked) {
if (assignButtonBWHWClicked.equals(assignButtonBWHWClicked)) {
assignFragment1 = new assignFragment1();
buttonsGeneric = new genericBackNextFragment();
splitItFragmentManager3 = getFragmentManager();
splitItFragmentTransaction3 = splitItFragmentManager3.beginTransaction();
splitItFragmentTransaction3.replace(R.id.fragment_container, assignFragment1);
splitItFragmentTransaction3.replace(R.id.fragment_container_2, buttonsGeneric);
splitItFragmentTransaction3.addToBackStack(null);
splitItFragmentTransaction3.commit();
Bundle bundleAssign = new Bundle();
bundleAssign.putDouble("price1", 22);
assignFragment1.setArguments(bundleAssign);
}
}
片斷:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
assignFragment1View = inflater.inflate(R.layout.assign_fragment_1, container, false);
item1 = (TextView) assignFragment1View.findViewById(R.id.assign1_food_item_1);
item2 = (TextView) assignFragment1View.findViewById(R.id.assign1_food_item_2);
priceItem1 = (TextView) assignFragment1View.findViewById(R.id.assign1_price_item_1);
priceItem2 = (TextView) assignFragment1View.findViewById(R.id.assign1_price_item_2);
Bundle bundleAssign = this.getArguments();
Double price1Double = bundleAssign.getDouble("priceItem1", 0.00);
priceItem1.setText(String.valueOf(price1Double));
return assignFragment1View;
}
謝謝非常!這解決了它。如何讓你可以百遍查看自己的代碼,而不是發現如此明顯的內容,這真是太神奇了。 –
修好了,接受它,如果它幫助:)所以它從未回答的問題隊列中清除:) –