传递参数DialogFragment [英] passing argument to DialogFragment
本文介绍了传递参数DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过一些变量 DialogFragment
,这样我就可以执行的操作。 Eclipse的建议,我应该使用
I need to pass some variables to DialogFragment
, so I can perform an action. Eclipse suggests that I should use
Fragment#setArguments(Bundle)
但我不知道如何使用此功能。我怎样才能用它来变量传递给我的对话?
But I don't know how to use this function. How can I use it to pass variables to my dialog?
推荐答案
使用的newInstance
public static MyDialogFragment newInstance(int num) {
MyDialogFragment f = new MyDialogFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
和获取参数数量像这样
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments().getInt("num");
...
}
请参阅完整的例子在这里
<一href="http://developer.android.com/reference/android/app/DialogFragment.html">http://developer.android.com/reference/android/app/DialogFragment.html
See the full example here
http://developer.android.com/reference/android/app/DialogFragment.html
这篇关于传递参数DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文