我有片段A,其中包含兩個按鈕(讓說ButtonA和ButtonB),同時按ButtonB我加載片段B(片段B包含1個按鈕,讓說按鈕C),而按下按鈕C,彈出窗口即將出現。片段回來按,加載回片段
我面對現在,當我返回按然後popwindow是disapperaing但裝載片段A.
其實我當popwindow在B片段中顯示需要,以及用戶按後退按鈕然後,彈出窗口只應該問題消失,它仍然在片段B,而不是片段A.
我做了什麼,從片段B我創建了一個接口,並通過一個活動中的Popwindow實例,並從活動我解散popwindow 。
@Override
public void onHandleRequest(PopupWindow popupWindow, PopupWindow backpopwindow, String fragmentName) {
if(fragmentName !=null){
this.fragmentName=fragmentName;
if(popupWindow!=null){
this.popupWindow=popupWindow;
this.backpopwindow=backpopwindow;
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
if(popupWindow!=null && popupWindow.isShowing()){
popupWindow.dismiss();
backpopwindow.dismiss();
}
}
在我的片段類:
public interface OnHandleCallBack{
public void onHandleRequest(PopupWindow popupWindow,PopupWindow backpopwindow,String fragmentName);
}
public void showPopup(View view, Context context,ArrayList<String> arrayList) {
if(popupWindow!=null && popupWindow.isShowing()){
popupWindow.dismiss();
}
mLayoutManager.setScrollEnabled(false);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Making transparent layout
final View popupView1 = inflater.inflate(R.layout.transparent_layout,
(ViewGroup) view.findViewById(R.id.transprent));
popupWindow1 = new PopupWindow(popupView1, WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);
popupWindow1.showAtLocation(popupView1, Gravity.CENTER, 0 , 0);
popupWindow1.setBackgroundDrawable(new BitmapDrawable());
popupWindow1.setOutsideTouchable(true);
popupWindow1.showAsDropDown(popupView1, 0, 0);
final View popupView = inflater.inflate(R.layout.my_order_truck_popup_win,
(ViewGroup) view.findViewById(R.id.popup_win));
RecyclerView mRecyclerView = (RecyclerView) popupView.findViewById(R.id.truck_recyler_id);
TextView textView=(TextView) popupView.findViewById(R.id.txt_truck);
RelativeLayout cancl_rl=(RelativeLayout)popupView.findViewById(R.id.rl_cncl);
textView.setText(context.getResources().getString(R.string.trucks));
Config.colorFont(context,null,textView,null);
popupView.setAnimation(AnimationUtils.loadAnimation(context, R.anim.pop_up_window));
/********* Here is my PopUp window ********/
Float m=TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, getResources().getDisplayMetrics());
int m1=Math.round(m);
popupWindow = new PopupWindow(popupView,m1,WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0 , 0);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
MyOrderPopUPAdapter mAdapter = new MyOrderPopUPAdapter(context, arrayList);
LinearLayoutManager LayoutManager = new LinearLayoutManager(context);
mRecyclerView.setLayoutManager(LayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setAdapter(mAdapter);
onHandleCallBack.onHandleRequest(popupWindow,popupWindow1,"orderfragment");
popupWindow1.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
popupWindow1.dismiss();
mLayoutManager.setScrollEnabled(true);
return true;
}
});
cancl_rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
popupWindow1.dismiss();
mLayoutManager.setScrollEnabled(true);
}
});
popupWindow.showAsDropDown(popupView, 0, 0);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
onHandleCallBack = (OnHandleCallBack)context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement onHandleCallBack");
}
}
什麼popwindow從延伸? –
@masoudvali當我點擊片段B中的按鈕C時,會出現Popwindow,這個程序員像這樣創建PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); –
我知道,我想知道它的類是基於alertdialog還是不是 –