1. Download our Official Android App: Forums for Android!

Apps How to add at a main layout an imageView controlled from another thread?

Discussion in 'Android Development' started by lugopaco, Oct 26, 2011.

  1. lugopaco

    lugopaco Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    Mar 31, 2011

    Mar 31, 2011
    30
    0
    15
    Student
    Mexico
    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:

    And the Image is not opened.

    Here is this code:

    Code (Text):
    1.   public class intsocketclient extends Activity implements  OnClickListener{
    2.         public ImageView imagen;
    3.             private Button connectPhones;              
    4.             private Handler conectarhandler = null;
    5.         private Runnable conectarunner = null;
    6.     public boolean condicion = true;
    7.            
    8.             @Override
    9.             protected void onCreate(Bundle savedInstanceState) {
    10.                 super.onCreate(savedInstanceState);
    11.                 setContentView(R.layout.main);      
    12.                 imagen = (ImageView) findViewById(R.id.imagen);
    13.                 connectPhones = (Button) findViewById(R.id.connect_phones);
    14.                 connectPhones.setOnClickListener(this);
    15.                
    16.                 conectarhandler = new Handler();        
    17.                 conectarunner = new Runnable() {
    18.                     public void run() {
    19.                     conectayenvia();
    20.                 conectarhandler.post(this);          
    21.                                
    22.                     }
    23.               };                    
    24.             }
    25.    
    26.     @Override
    27.     public void onClick(View v) {
    28.         // TODO Auto-generated method stub.
    29.          if(v==connectPhones) {                  
    30.              new Thread (conectarunner).start();                    
    31.          }
    32.     }
    33.    
    34.     public void conectayenvia () {
    35.         if (condicion){                
    36.                       condicion = false;
    37.                       Bitmap bMap = BitmapFactory.decodeFile("/sdcard/recibido.jpg");
    38.                       imagen.setImageBitmap(bMap);                                          
    39.          }    
    40.         }    
    41.     }
    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????????
     

    Advertisement

Share This Page

Loading...