我有一个线性布局和一个框架布局,我在框架布局中膨胀我的片段,如何从片段

时间:2016-09-04 07:29:05

标签: android android-layout android-fragments layout

<RelativeLayout
...>
<LinearLayout
...>
<TextView
.../>
</LinearLayout>
<FrameLayout
.../>
</RelativeLayout>

在我的主要活动中:

我在框架布局中替换我的片段,如何从我的片段类中访问线性布局。

错误:

只有在实际创建视图的地方才能访问。

1 个答案:

答案 0 :(得分:1)

您可以使用

Activity Fragment访问Layout yourLayout = (Layout)getActivity().findViewById(R.id.idOfLayout);中的任何布局

getActivity()

片段可以将Activity实例与private void DataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = this.DataGridView2.Rows[e.RowIndex]; textBox1.Text = row.Cells["HomeNM"].Value.ToString(); textBox3.Text = row.Cells["HostNM"].Value.ToString(); fromTxt.Text = row.Cells["odd1NM"].Value.ToString(); } } 一起使用,例如在活动布局中查找视图