Android: findviewbyid: finding view by id when view is not on the same layout invoked by setContentView

前端 未结 5 2054
陌清茗
陌清茗 2020-12-08 04:02

I have an activity MyActivity that extends from MapActivity. In the .xml file containing the layout I can only include the MapView



        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 04:29

    Another way to do this is:

    // inflate the layout
    View myLayout = LayoutInflater.from(this).inflate(R.layout.MY_LAYOUT,null);
    
    // load the text view
    TextView myView = (TextView) myLayout.findViewById(R.id.MY_VIEW);
    

提交回复
热议问题