将数据从活动发送到 Android 中的片段 [英] Send data from activity to fragment in Android
本文介绍了将数据从活动发送到 Android 中的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个班级.第一个是活动,第二个是我有一些 EditText
的片段.在活动中,我有一个带有异步任务的子类,在方法 doInBackground
中,我得到了一些结果,并将其保存到变量中.如何将此变量从子类我的活动"发送到此片段?
I have two classes. First is activity, second is a fragment where I have some EditText
. In activity I have a subclass with async-task and in method doInBackground
I get some result, which I save to variable. How can I send this variable from subclass "my activity" to this fragment?
推荐答案
从 Activity 你发送数据的目的是:
From Activity you send data with intent as:
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);
在 Fragment onCreateView 方法中:
and in Fragment onCreateView method:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext = getArguments().getString("edttext");
return inflater.inflate(R.layout.fragment, container, false);
}
这篇关于将数据从活动发送到 Android 中的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文