从活动将数据发送到片段中的机器人 [英] Send data from activity to fragment in android

查看:113
本文介绍了从活动将数据发送到片段中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个班。首先是活动的,第二个是一个片段,我有一些edittexts。在活动我有一个子类,异步任务和方法 doInBackground 我得到了一些成绩,这是我保存到变量。我如何发送此变量子我的活动这个片段?

I have two classes. First is activity, second is a fragment where I have some edittexts. 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?

推荐答案

从活动发送的数据,意图​​为:

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);

和在片段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);
}

这篇关于从活动将数据发送到片段中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆