<RelativeLayout
...>
<LinearLayout
...>
<TextView
.../>
</LinearLayout>
<FrameLayout
.../>
</RelativeLayout>
在我的主要活动中:
我在框架布局中替换我的片段,如何从我的片段类中访问线性布局。
错误:
只有在实际创建视图的地方才能访问。
答案 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();
}
}
一起使用,例如在活动布局中查找视图