Android Dialogfragment
onclicklistner
单独的课程如何解雇
我在onCreateView
方法上创建了对话框视图。
我的代码
片段对话
public class ShareDialogFragment extends DialogFragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
String articleID;
MultiAutoCompleteTextView myMultiAutoCompleteTextView;
TextView Cancel;
Context context;
OnClickListenerCustom onClickListenerCustom;
String item[]={
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
public ShareDialogFragment() {
}
public static ShareDialogFragment newInstance(String param1, String param2) {
ShareDialogFragment fragment = new ShareDialogFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
//ThemeOverlay_Material_Light
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.alert_dialog);
final Dialog dialog = new Dialog(getActivity());
Bundle arg = getArguments();
if(arg!=null){
articleID = getArguments().getString("ArticleId");
}
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
context = activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_share_dialog, container, false);
Cancel = (TextView)view.findViewById(R.id.Cancel);
onClickListenerCustom = new OnClickListenerCustom(context);
Cancel.setOnClickListener(onClickListenerCustom);
myMultiAutoCompleteTextView = (MultiAutoCompleteTextView)view.findViewById(R.id.editText);
myMultiAutoCompleteTextView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, item));
myMultiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
return view;
}
}
OnClickListenerCustom
切换案例热点拒绝Dialog Fragment
public class OnClickListenerCustom implements OnClickListener {
public Context context;
String articleId, CompID;
public int articlePost;
public OnClickListenerCustom(Context context, String articleId, String CompID,int articlePost) {
this.context = context;
this.articleId = articleId;
this.CompID = CompID;
this.articlePost = articlePost;
}
public OnClickListenerCustom(Context context){
this.context = context;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.starImage:
v.setActivated(!v.isActivated());
if (v.isActivated()) {
PatApi.isFavorites(articleId, "add", "article");
} else if (!v.isActivated()) {
PatApi.isFavorites(articleId, "remove", "article");
}
break;
case R.id.imagePat:
v.setActivated(!v.isActivated());
PatApi.isPat(CompID, articleId, "3");
break;
case R.id.share:
FragmentManager manager = ((Activity) context).getFragmentManager();
Bundle arg= new Bundle();
arg.putString("ArticleId",String.valueOf(articlePost));
ShareDialogFragment msgDialog = new ShareDialogFragment();
msgDialog.show(manager,"Dialog");
msgDialog.setArguments(arg);
break;
case R.id.RelativeWrapper:
Intent i = new Intent(v.getContext(), ArticleView.class);
v.getContext().startActivity(i);
break;
case R.id.favoritesSwipe:
v.setActivated(!v.isActivated());
if (v.isActivated()) {
PatApi.isFavorites(articleId, "add", "article");
} else if (!v.isActivated()) {
PatApi.isFavorites(articleId, "remove", "article");
}
break;
case R.id.imageFavorites:
// v.setActivated(!v.isActivated());
M.t(context, "IMAGES");
break;
case R.id.Cancel:
M.t(context, "Dismiss ");
//how to Dismiss oc Click
/*
ShareDialogFragment superSimpleDlg = new ShareDialogFragment();
superSimpleDlg.dismiss();*/
break;
}
}
}
答案 0 :(得分:0)
尝试
popupWindow.dismiss();
答案 1 :(得分:0)
试试这个......
ShareDialogFragment类的变化-------
全局宣布对话......
Dialog dialog;
在onCreate方法初始化..
dialog = new Dialog(getActivity());
并在onCreateView
中 onClickListenerCustom = new OnClickListenerCustom(context, dialog);
OnClickListenerCustom类的变化----
全球宣布......
Dialog dialog;
构造函数
public OnClickListenerCustom (Context context, Dialog dialog){
this.context = context;
this.dialog = dialog;
}
和
case R.id.Cancel:
M.t(context, "Dismiss ");
//how to Dismiss oc Click
dialog.dismiss();
break;
希望这会对你有帮助......