Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old October 26th, 2011, 12:13 PM   #1 (permalink)
Junior Member
 
Join Date: Mar 2011
Location: Mexico
Posts: 30
 
Device(s): Samsung Galaxy 5 (GT-I5500L), Samsung Galaxy Ace
Thanks: 11
Thanked 2 Times in 2 Posts
Sad How to add at a main layout an imageView controlled from another thread?

Hi!! I'm making an app for Android. I have reached my goal with the single main thread pushing a button!!! (show an image saved on the SD in an ImageView) But I need to do it with threading to save some time and because I will make other threads.

The problem when I do this on a new thread a warning appears that tells me:

Quote:
"Only the original thread that created a view hierachy can touch its
views."
And the Image is not opened.

Here is this code:

Code:
  public class intsocketclient extends Activity implements  OnClickListener{
        public ImageView imagen;
            private Button connectPhones;               
            private Handler conectarhandler = null;
        private Runnable conectarunner = null;
    public boolean condicion = true;
            
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);      
                imagen = (ImageView) findViewById(R.id.imagen);
                connectPhones = (Button) findViewById(R.id.connect_phones);
                connectPhones.setOnClickListener(this);
                
                conectarhandler = new Handler();         
                conectarunner = new Runnable() { 
                    public void run() {
                    conectayenvia(); 
                conectarhandler.post(this);          
                               
                    }
              };                    
            }
    
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub.
         if(v==connectPhones) {                  
             new Thread (conectarunner).start();                    
         }
    }
    
    public void conectayenvia () {
        if (condicion){                 
                      condicion = false;
                      Bitmap bMap = BitmapFactory.decodeFile("/sdcard/recibido.jpg");
                      imagen.setImageBitmap(bMap);                                           
         }    
        }    
    }
But I really need it to be this way.

Is it possible to take the main layout (the original "main.xml") and some kind of "add" over it another main file (a "threadmain.xml" which only contains the imageView)but also with the capability of pushing buttons and other kind of things of the first original "main.xml" layout????????

lugopaco is offline  
Reply With Quote
Sponsors
Reply

Bookmarks

Tags
android, imageview, layout, thread


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:10 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo