Android 从不同布局访问对象

Android 从不同布局访问对象,android,layout,Android,Layout,我有两种布局称为“活动\纵向”和“活动\横向”。 如何从不在屏幕上的活动访问对象,例如 setContentView(R.layout.activity_portrait); //... // here need to access object from activity_landscape // for instance to set some buttonText 您需要先将布局充气,然后才能访问其中的项目,但这不是一个好主意 View v = //

我有两种布局称为“活动\纵向”和“活动\横向”。 如何从不在屏幕上的活动访问对象,例如

     setContentView(R.layout.activity_portrait);

    //...
    // here need to access object from activity_landscape
    // for instance to set some buttonText

您需要先将布局充气,然后才能访问其中的项目,但这不是一个好主意

View v = // inflate the layout

View yourViewItem = v.findViewItemById etc

你为什么要这么做?这通常是个可怕的主意。你应该看看