gpt4 book ai didi

java - 我有一个 Activity ,当用户单击其中的卡片时,它会转到一个 fragment ..并返回到该 Activity 如何销毁该 fragment ?

转载 作者:行者123 更新时间:2023-12-02 09:23:32 25 4
gpt4 key购买 nike

enter image description here我想在用户选择订单日期和交货日期时停止 fragment 。

我有一个 Activity ,其中有两张卡 oderDate 和 DeliveryDate,当用户单击其中任何一张时,它会转到一个 fragment 来选择日期,我想在用户选择日期时停止该 fragment 。

orderActivity.xml

 orderDateCard.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
isOrder = 1; // setting orderCard is true
isDel = 0;

fragmentContainer.setVisibility(View.VISIBLE);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
calender_view_fragment calender_view_fragment = new calender_view_fragment();
fragmentTransaction.add(R.id.fragmentContainer, calender_view_fragment);
fragmentTransaction.commit();


}
});
delDateCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
isDel = 1; //setting deliveryCard is true
isOrder = 0;

fragmentContainer.setVisibility(View.VISIBLE);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
calender_view_fragment calender_view_fragment = new calender_view_fragment();
fragmentTransaction.add(R.id.fragmentContainer, calender_view_fragment);
fragmentTransaction.commit();
}
});

calender_view_fragment.xml

calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int selectedYear, int selectedMonth, int selectedDate) {
orderYear = selectedYear;
orderMonth = selectedMonth + 1;
orderDate = selectedDate;


calenderViewText.setText("PICK DELIVERY DATE");
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int selectedYear, int selectedMonth, int selectedDate) {
delDate = selectedDate;
delMonth = selectedMonth + 1;
delYear = selectedYear;
startOrderActivity();
stopCurrentFragment();


}
});


}
});
}

public void stopCurrentFragment(){



calender_view_fragment calender_view_fragment=new calender_view_fragment();
getFragmentManager().beginTransaction().remove(calender_view_fragment).commitAllowingStateLoss();


}

最佳答案

试试这个代码:

getFragmentManager().popBackStack()

关于java - 我有一个 Activity ,当用户单击其中的卡片时,它会转到一个 fragment ..并返回到该 Activity 如何销毁该 fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58499805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com