从我的活动中获取数据到我的片段 [英] getting data to my fragment from my activity

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

问题描述

我终于有了一些研究如何让我的 dialogfragment 将结果发送到我的活动,现在我想通过这些结果真的是片段后想通了一条要求该对话框片段(这是一个日期选择器,所以我想更新的日期)。

I finally figured out after some research how to get my dialogfragment to send the results to my activity, now I want to pass those results to the fragment that really is the one calling that dialog fragment (it's a date picker so I want to update the date).

我看到这个在这里:呼叫从活动片段事件

以上给了我一些想法,但由于某些原因,我的片段布局在一个XML定义的,它没有身份证,所以我不能使用呼叫:

The above gave me some ideas but for some reason, my fragments layout is defined in an XML and has no id with it so I cannot use the call:

findFragmentById(R.id.fragmentBId);

所以我无论是在XML定义我的布局(这是我的片段)错误的,或者还有另一种方式去了解这一点。

So I'm either defining in the xml my layout (That is my fragment) wrong, or there is another way to go about this.

我的XML布局中有我的整个布局(所有的按钮textviews linearlayouts等)。虽然我从来没有一次说<片段... /> 。但我确实进一步调查,看到这个页面上:

My xml layout has my entire layout (all the buttons textviews linearlayouts etc) in it. Though I never not once say <fragment .... />. But I did investigate further and saw on this page:

http://developer.android.com/guide/topics/fundamentals/ fragments.html

这是怎么应该定义片段。所以,完整性,这里是我的xml文件,现在给了我一个错误:在哪里我定义片段行充气类片段错误

That is how one supposed to define the fragment. So for completeness here is my xml file that now gives me an Error: inflating class fragment error on the line where I define the fragment.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <fragment android:name="com.viciousbytes.studiotab.subactivities.SessionEdit"
        android:id="@+id/session_fragment"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent">  
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">    
      <TextView         
            android:textSize="20sp"
            android:text = "Client Name:" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"/>         
    <TextView 
        android:id="@+id/client_name"
        android:gravity="center"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>       
</LinearLayout> 
    etc...
    etc...
    </fragment>
</LinearLayout>

所以我缺少什么?还是通过id /我指的应该指向中有这一切的UI另一个XML?我有点困惑如何要我设置起来。这是工作不片段标记,但后来我没有办法拨打:

So what am I missing? or does the id/ i refer to should point to another xml that has all this UI in it? I am a bit confused about how it wants me to set this up. It was working without the fragment tag but then I had no way to call:

SessionEdit session = (SessionEdit)getSupportFragmentManager().findFragmentById(R.id.session_fragment);

我只是想有我的对话日期选取器发送信息,以调用它的片段。结果
我已经看到了对话的日期选择器的演示,但我不得不改变它使用 DialogFragment ,我必须错过了JIST。

I just want to have my dialog date picker send info to the fragment that called it.
I had seen the dialog date picker demo but I had to change it to use the DialogFragment and I must of missed the "jist".

推荐答案

&LT;片断&gt;不是一个容器,它不能有任何的儿童。你应该做的是有你的片段类设置的内容,以便你在这里为的&lt的孩子的东西;片断&gt;标签。片断&gt;你这里的&LT的内容;应该生活在自己的XML文件中。

<fragment> is not a container, it can not have any children. What you should do is have your Fragment class set its content view to what you have here as the children of the <fragment> tag. The contents you have here of <fragment> should live in its own XML file.

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

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