You can launch an Activity through broadcast receiver. that can change the
textview colour..

On Sun, Jan 15, 2017 at 4:02 AM, abdullah zaman <
engr.abdullahza...@gmail.com> wrote:

> How can I use findViewById() in a Broadcast Receiver class. Below is my
> code snippet. I get the error message: "can't resolve method findViewById"
> if used directly without class constructor (because find View by Id is
> Activity method and cant be used in Broadcast Receiver i suppose) . And if
> i try to use the class constructor (Where the imageView is available in my
> main activity) my app crashes saying " Unfortunately app has stopped" .
>
>  I just want to change the color of ImageView e.g "from black to blue" in
> the below if statement if it is possible by any other means pleas let me
> know.
>
> This is my Broadcast Receiver class
>
> public class MyBroadcastReceiver extends FirstBroadcastReceiver {
> Context context;Activity activity;public MyBroadcastReceiver(Context context, 
> Activity activity){
>     this.context=context;
>     this.activity=activity;}
>
>     @Override
>     protected void (Context context) {
>     // content
>     }
>
>     @Override
>     public void onButton(Context context, boolean isClick) {
>
>         if(isClick) {
>
>     ImageView blueImage = (ImageView) activity.findViewById(R.id.imageView);
>     blueImage.setColorFilter(0xff000000);
>          }
>     }...........
>     // and so on
>
> And this is my Main Activity
>
> public class MainActivity extends AppCompatActivity {
> @Overrideprotected void onCreate(Bundle savedInstanceState) {
>     super.onCreate(savedInstanceState);
>     setContentView(R.layout.activity_main);
>      // and so on
>     }}
>
> MyBroadcastReceiver myBroadcastReceiver = new 
> MyBroadcastReceiver(MainActivity.this,this);
>
>  @Override
>  public void onActivityResult() {
>   // some code
>   }
> @Override
>      public void onInitialized(MyManager manager){
>  // some code
>  }
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to android-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/android-developers/31c0874e-3c84-4f1a-b17d-
> 85cde28741ec%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/31c0874e-3c84-4f1a-b17d-85cde28741ec%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CABHzXAS_bVowxdvomLrnL3aJTyYutyFHGRVXnL_RCbh0bBvcVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to