如何让一个片段添加一个XML布局 [英] how to get a fragment added in an XML layout

查看:126
本文介绍了如何让一个片段添加一个XML布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,其中包括一个片段如下:

I have a layout which includes a fragment as follows:

<fragment
        android:id="@+id/mainImagesList"
        android:name="com.guc.project.ImagesList"
        android:layout_width="match_parent"
        android:layout_height="62dp"
        android:layout_below="@+id/addimagebutton"
        android:layout_weight="1"
        android:paddingTop="55dp" />

现在,我需要得到这个片段,并投它,所以我可以操纵它,并更新显示。我怎么可以这样做?!

now, I need to get this fragment and cast it so I can manipulate it and the updates appear. How can i do so ?!

编辑:我想我已经成功地得到了片段,但是当我改变了一些变数,所做的更改不会出现

I think I've managed to get the fragment, but when I change some variables, the changes don't appear !

推荐答案

您可以得到这样的片段实例:getSupportFragmentManager()findFragmentById(R.id.mainImagesList)

you can get the fragment instance like this : getSupportFragmentManager().findFragmentById(R.id.mainImagesList)

这篇关于如何让一个片段添加一个XML布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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