我正在尝试获取我创建的 LinearLayout 中的 fragment :
编辑:这是在扩展 ArrayAdapter<G>
的类中
LinearLayout newView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li = (LayoutInflater) getContext().getSystemService(inflater);
li.inflate(resource, newView, true);
布局中有一个名为 TableRowView 的 fragment :
编辑:我更正了 XML 语法
<fragment android:name ="mypackage.TableRowView"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我如何获得 newView
的 fragment ?
提前致谢, --大卫
最佳答案
I am trying to get a hold of a fragment that is within a LinearLayout I have created
fragment 不在 LinearLayout
中。 fragment 不是 View
,也不驻留在 ViewGroup
中。 onCreateView()
中的 fragment 创建的 View
将驻留在 ViewGroup
中。
I am trying to get a hold of a fragment that is within a LinearLayout I have created
尝试在 FragmentManager
上调用 findFragmentById()
,前提是您在膨胀操作之前在 newView
上设置了一个 ID。
关于Android:在动态创建的布局中查找 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899753/