我有一個popupWindow,用於修改在父窗口中加載微調器的SQLight表。我想讓父窗口中的微調框在刷新PopupWindow時用新值刷新。下面的代碼顯示了我的進度創建一個偵聽器,可以檢測PopupWindow的解僱。我迄今爲止的聽衆不工作。我認爲我已經錯過了構建聽衆的東西。我已經包含ShowPopup類以及作爲此窗口的父級的片段(Tab3Fragment)。在PopupWindow.dismiss上刷新父級片段
showPopup.java
public class showPopup extends PopupWindow{
Context m_context;
Button btnDismiss;
PopupWindow popup;
Tab3Fragment Tab3Fragment;
OnDismissListener listener;
public showPopup(Context context){
super(context);
m_context = context;//was commented out
setContentView(LayoutInflater.from(context).inflate(R.layout.popup_layout, null));
setHeight(LayoutParams.WRAP_CONTENT);
setWidth(LayoutParams.WRAP_CONTENT);
}
public void init(View v){
LayoutInflater inflater = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popUpView = inflater.inflate(R.layout.popup_layout, null, false);
final PopupWindow popup = new PopupWindow(popUpView, 600, 400, true);
popup.setContentView(popUpView);
popup.showAtLocation(v, Gravity.CENTER_HORIZONTAL, 0, 0);
btnDismiss = (Button) popUpView.findViewById(R.id.btndismissxml);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View anchor) {
popup.dismiss();
}
});
}
@Override
public void setOnDismissListener(OnDismissListener listener){
this.listener = listener;
}
}
Tab3Fragment.java
public class Tab3Fragment extends Fragment implements OnClickListener{
Context context;
Button btnPopup, btnSpinnerRefresh;
Spinner spinnerSpecies;
public static int iSpeciesPosition;
showPopup showPopup;
ArrayAdapter<String> arrayAdapterSpecies;
OnDismissListener dismissListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup containerGroup, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab3_fragment, containerGroup, false);
btnPopup = (Button)v.findViewById(R.id.btnPopupxml);
btnPopup.setOnClickListener(this);
btnSpinnerRefresh = (Button)v.findViewById(R.id.btnSpinnerRefreshxml);
btnSpinnerRefresh.setOnClickListener(this);
spinnerSpecies = (Spinner) v.findViewById(R.id.spinnerSpeciesxml);
spinnerSpecies.setAdapter(arrayAdapterSpecies);
if(savedInstanceState != null){
iSpeciesPosition = savedInstanceState.getInt("speciesPosition_key");
populateTab3Fragment(v);
}else if(savedInstanceState == null){
populateTab3Fragment(v);
}
return v;
}
//@Override
public void onViewCreated(View v) {
populateTab3Fragment(v);
/******************************************************************************************************
Can setOnDismissListener be used outside of showPopup class to indicate that showPopup has dismissed?
******************************************************************************************************/
showPopup popup = new showPopup(context);
popup.setOnDismissListener(new OnDismissListener(){
@Override
public void onDismiss(){
Toast.makeText(getActivity().getApplicationContext(), "onDismiss() works.", Toast.LENGTH_LONG).show();
loadSpinnerData();
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnPopupxml:
new showPopup(getActivity().getApplicationContext()).init(v);
break;
case R.id.btnSpinnerRefreshxml:
loadSpinnerData();//temporary workaround to refresh spinner...
break;
}
}
/**
* Function to load the spinner data from SQLite database
* */
public void loadSpinnerData() {
//omitted
}
public void populateTab3Fragment(View v){
loadSpinnerData();
}
}
好的 - 我已經廣泛修改showPopup類並刪除了無關的語言。是否有可能在正在被解散的popupWindow類之外實現onDismissListener()?我在這裏錯過了什麼? TIA顯示耐心並提供有用的反饋。 – portsample 2015-01-12 04:16:33