android - How to get view from context?

后端 未结 5 851
走了就别回头了
走了就别回头了 2020-12-01 04:26

I want to get the view or findViewById() from Context? Or from intent?

I\'m trying to reach a specific view in my broadcast receiver and the parameter of onReceive a

5条回答
  •  遥遥无期
    2020-12-01 04:57

    In your broadcast receiver you could access a view via inflation a root layout from XML resource and then find all your views from this root layout with findViewByid():

    View view = View.inflate(context, R.layout.ROOT_LAYOUT, null);
    

    Now you can access your views via 'view' and cast them to your view type:

    myImage = (ImageView) view.findViewById(R.id.my_image);
    

提交回复
热议问题