提问人:neuron soft 提问时间:11/7/2023 更新时间:11/7/2023 访问量:14
Android、DialogModal 添加 FragmentContainerView
Android, DialogModal add FragmentContainerView
问:
我有一个 ModalReplenishment.class,我使用以下方法从 BillingsListOneFragment.class 调用它
private void handlerBtnReplenishment(Billings bill){
ModalReplenishment modalReplenishment = new ModalReplenishment(getContext(),bill);
modalReplenishment.modalStart(new DialogCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(Exception exception) {
}
});
}
全码模态补货.class
public class ModalReplenishment implements DialogModal{
private ImageView imageViewBillingCard;
private TextView tVNameBilling, tVABillingBalance, tVTypeCurrency, tVTypeBilling;
private ToggleButton toggleBtnIncome, toggleBtnTheBill;
private Billings billing;
private Context context;
private Dialog dialogModal;
public ModalReplenishment(Context context, Billings billing) {
this.context = context;
this.billing = billing;
}
@Override
public void modalStart(DialogCallback dialogCallback) {
showDialogModal();
setupUIDialogModal();
setValueObjectModal();
handlerButtonDialogModal(dialogCallback);
}
@Override
public void showDialogModal() {
dialogModal = new Dialog(context);
dialogModal.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogModal.setContentView(R.layout.modal_bottom_replenishment);
dialogModal.show();
dialogModal.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialogModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogModal.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialogModal.getWindow().setGravity(Gravity.BOTTOM);
}
@Override
public void setupUIDialogModal() {
this.toggleBtnIncome = dialogModal.findViewById(R.id.toggleBtnIncome);
this.toggleBtnTheBill = dialogModal.findViewById(R.id.toggleBtnTheBill);
this.imageViewBillingCard = dialogModal.findViewById(R.id.imageView_modal_account_card);
this.tVNameBilling = dialogModal.findViewById(R.id.textView_modal_name_account);
this.tVABillingBalance = dialogModal.findViewById(R.id.textView_modal_balance_account);
this.tVTypeCurrency = dialogModal.findViewById(R.id.textView_modal_type_currency);
this.tVTypeBilling = dialogModal.findViewById(R.id.textView_type_account);
}
@Override
public void handlerButtonDialogModal(DialogCallback dialogCallback) {
handlerToggleButton();
}
private void handlerToggleButton(){
toggleBtnIncome.setOnClickListener(v->{
switcherToggleButton(toggleBtnIncome);
});
toggleBtnTheBill.setOnClickListener(v->{
switcherToggleButton(toggleBtnTheBill);
});
}
private void switcherToggleButton(ToggleButton toggleButton) {
if(toggleBtnIncome == toggleButton){
toggleBtnTheBill.setChecked(false);
toggleBtnTheBill.setTextColor(context.getResources().getColor(R.color.gray));
toggleBtnIncome.setChecked(true);
toggleBtnIncome.setTextColor(context.getResources().getColor(R.color.black));
showFragReplenishment();
}
if(toggleBtnTheBill == toggleButton){
toggleBtnIncome.setChecked(false);
toggleBtnIncome.setTextColor(context.getResources().getColor(R.color.gray));
toggleBtnTheBill.setChecked(true);
toggleBtnTheBill.setTextColor(context.getResources().getColor(R.color.black));
showFragReplenishment();
}
}
private void setValueObjectModal() {
switcherToggleButton(toggleBtnIncome);
imageViewBillingCard.setImageResource(TypeBillings.getIdImageTypeBillings(billing.getTypeBillings()));
tVNameBilling.setText(billing.getName());
tVABillingBalance.setText(String.valueOf(billing.getBalance()));
tVTypeCurrency.setText(billing.getTypeCurrency());
tVTypeBilling.setText(billing.getTypeBillings());
}
private void showFragReplenishment() {
Fragment selectedFragment;
if (toggleBtnIncome.isChecked()) {
selectedFragment = new IncomeFragment(); // Створіть фрагмент для доходів
} else {
selectedFragment = new TheBillFragment(); // Створіть фрагмент для рахунку
}
FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragContainerReplenishment, selectedFragment); // Оновіть ідентифікатор на fragContainerReplenishment
transaction.commit();
}
当我已经调用showFragReplenishment()时,我得到一个异常
java.lang.IllegalArgumentException: No view found for id 0x7f080294 (com.example.monefy:id/fragContainerReplenishment) for fragment IncomeFragment{e69585f} (15d3592f-20d2-4b93-8549-823b43dd61e9 id=0x7f080294)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
id 元素正确 FragmentContainerView @+id/fragContainerReplenishment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragContainerReplenishment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.fragment.app.FragmentContainerView>
当我显示FragReplenishment()时,我需要相应地加载片段的内容。
答: 暂无答案
评论