Update ImageView from outside

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Update ImageView from outside

Postby ansh.chauhan » Wed Sep 21, 2011 12:54 pm

Hi
Can you tell me how we can update Image view outside onCreate.

Ex:-

I have create on class A extend Activity{
Imageview img;
onCreate(){
img=(ImageView)findViewbyId(R.id.img1);
}

//Iner class
class B{
I want to Update Image view from here.
}


}


Tell me how to update imageview from classB.
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Top

Re: Update ImageView from outside

Postby redbulletnl » Wed Sep 21, 2011 3:49 pm

maybe with a subclass?
redbulletnl
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Sep 14, 2011 7:44 am

Re: Update ImageView from outside

Postby MichaelEGR » Wed Sep 21, 2011 4:47 pm

From inner class B you can call the method "runOnUiThread(Runnable action)" directly of A which extends Activity.

So whatever method you create in B would do something like this:

Code: Select all
class B {
    public void updateImage() {
        runOnUiThread(new Runnable() {
           public void run() {
              img.setImageBitmap(<BITMAP>)  // or any setImage variant
           }
        }
    }
}


You might need to define img as final when accessing it from an anonymous Runnable.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Return to General

Who is online

Users browsing this forum: No registered users and 7 guests