所以我正在处理其中有2个片段的片段。看看下面的图片:
显示库存清单的第一个片段名为 fragment_purchase_item_list ,右侧是 fragment_purchase_list
我想做的是,当我从右侧片段的工具栏中单击 SCAN (扫描)时, fragment_qrscan 将替换 fragment_purchase_item_list 。就像下面的图片一样:
有人可以查看并检查为什么我的代码不起作用吗?谢谢!
PurchaseListFragment.java
def has_digit(str):
return any(char.isdigit() for char in str)
new_df=df[len(df['value1'])>=2 and not df['value1'].startswith("nn") and not has_digit(df['value1'])]
fragment_sales.xml
<-- start of code snippet -->
@Override
public void onClick(View v) {
int id = v.getId();
switch (id){
case R.id.btn_paypurchasetransaction:
Fragment chargeFragment = new ChargeFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.customersales_content, chargeFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
break;
case R.id.layout_transaction_qrcode:
// Toast.makeText(getActivity(), "Scan Item", Toast.LENGTH_SHORT).show();
Fragment scanQRCodeFragment = new QRScanFragment();
FragmentManager fragmentManager1 = getFragmentManager();
FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
fragmentTransaction1.replace(R.id.inventory_fragment, scanQRCodeFragment);
fragmentTransaction1.addToBackStack(null);
fragmentTransaction1.commit();
break;
case R.id.layout_transaction_new:
Toast.makeText(getActivity(), "New Transaction", Toast.LENGTH_SHORT).show();
break;
}
}
<-- end of code snippet>
答案 0 :(得分:1)
尝试将getFragmentManager()
替换为getChildFragmentManager()