title: android, creating/updating view from a method class running in an async task
body: <p>well i'm having some problem with android. Maybe its simple but i'm pretty new in android world (3, 4 days actually). Well i have an activity whitch runs an asyncTask that stands to reading data from a sensor network. The async Task only executes the function l.read() that by itself is a loop and keep allways "earing" the sensor network and when a new node joins to the sensor network, it tells the UI thread that one more node has joined, and so it has to update the view (witch has just one tab saying that no nodes exists and will now have to have one node available - besides this i even have to load an xml layout file for this tab ) the problem is that, when i preform the function that supostly creates a view and add a tab (that is properly working because when i call it on onCreate it works) the app do not respond anymore, however, Logcat gives me no errors. It look like it works but it is not showing anything.</p>
  
  <p>Please, i dont expect you to read all this code, its just to hel to explain my problem. Its been 2 days and i'm still asking for a solution..</p>
  
  <p>main Activity:</p>
  
  <pre><code>public class PrincipalActivity extends Activity implements OnClickListener
  {
  
  private Button Send;
  private Button Options;
  private TextView ERROR;
  private Bundle extras;
  private String IP;
  private String PORT;
  private TabHost tabs;
  private ligação l;
  View m_vForm;
  TabHost tabHost;
  CustomView Cview;
  ReadsData read;
  
  
  
  //constructor
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      CustomView vv = new CustomView(PrincipalActivity.this,0);
      setContentView(vv);
  
      //instanciating the objects
      IP = new String();
      PORT = new String();      
      extras = getIntent().getExtras();
      IP = extras.getString("IP");  //get the IP and port from the previous activity
      PORT = extras.getString("PORT");
      ERROR = (TextView) findViewById(R.id.ERROR);   
      tabs = (TabHost) findViewById(R.id.tabhost);
      tabs.setup();
      Send = (Button) findViewById(R.id.SendCommand);
      Send.setOnClickListener(this);
      Options = (Button) findViewById(R.id.Options);
      Options.setOnClickListener(this);
    //=========================
  
      CreateAView("No Nodes",false);
      l = new ligação(IP, Integer.parseInt(PORT),this);  //CLASS LIGAÇÃO
     // RunnableThread rT1 = new RunnableThread("t1",l,this);
  
      read = new ReadsData();
      read.execute();
  
      //Textviews (Values)
  
  
  }
  
  public void AddUpdateNodes(Nodes n,int func)
  {
      //func is 0 if it it to add a node or 1 if it is to update an existing one
      if(func == 0)
      {
          String s = new String();
          s+= n.GETSourceNodeID();
          CreateAView(s, true);
          Cview.addNewNode(n);        
      }
      if(func == 1)
          Cview.UpdateNodeInformation(n);
  }
  
  
  public void onClick(View v) 
  {
  
      if(v == Send)
      {
          // if i call CreateAView here it works ok
          ERROR.setText(IP);
  
      }
  
      if(v == Options)
      {
  
          ERROR.setText(PORT);
      }
  }
  
      // CREATING A VIEW WITH THE TABS
  public void CreateAView(String s,boolean nodesAvailable)
  {
  
       m_vForm = createTABForm(s,nodesAvailable);
       setContentView(m_vForm);
  }
  
   private ViewGroup createTABForm(String s,boolean nodesAvailable1)
   {
      final boolean nodesAvailable = nodesAvailable1;
  
          // construct the TAB Host
          tabHost = new TabHost(this);
          tabHost.setLayoutParams(  new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)  );
  
          // the tabhost needs a tabwidget, that is a container for the visible tabs
          TabWidget tabWidget = new TabWidget(this);
          tabWidget.setId(android.R.id.tabs);
          tabWidget.setBackgroundColor(Color.BLUE);
  
          tabHost.addView(tabWidget, new LinearLayout.LayoutParams(      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)   ); 
  
          // the tabhost needs a frame layout for the views associated with each visible tab
          FrameLayout frameLayout = new FrameLayout(this);
          frameLayout.setId(android.R.id.tabcontent);
          frameLayout.setPadding(0, 65, 0, 0);
          tabHost.addView(frameLayout, new LinearLayout.LayoutParams(   LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)   ); 
  
          // setup must be called if you are not initialising the tabhost from XML
          tabHost.setup(); 
  
          // create the tabs
          TabSpec ts = tabHost.newTabSpec("TAB_TAG_2");
          ts.setIndicator(s); // creating a tabb with the specified name
          ts.setContent(new TabHost.TabContentFactory(){
               public View createTabContent(String tag)
               {
                   // -- this tab contains a single control - the listview -- //
                   Cview = new CustomView(PrincipalActivity.this,nodesAvailable);
                   return Cview;   // IS AN OBJECT FROM THE CLASS CustomView
               }
          });
  
          tabHost.addTab(ts); 
          return tabHost;
      } 
  
  
  
  
   ////////////////////////////////////////////////////////////////
   //Async Tasks
   private class ReadsData extends AsyncTask 
   {
  
      @Override
      protected Object doInBackground(Object... params) 
      {
          l.read();
          return null;
      }
  
      protected void onPostExecute()
       {
          l.SocketClosed_();
       }
   }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    //CLASS CUSTOM VIEW
  
   public CustomView(Context context,boolean NodesAvailable)
   {
     super(context);
  
     if(NodesAvailable) //loads a layout
     {
         LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
         View view=layoutInflater.inflate(R.layout.finallayout,this);
  
         //only after inflate
          ADC0 = (TextView) findViewById(R.id.ADC00);
  
     }
     else  // loads another layout
     {
         LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View view=layoutInflater.inflate(R.layout.no_nodes,this);
     }
  
   }
  
  
  
   public void addNewNode(Nodes n)
   {
       String s = new String();
  
  
       s = new String();
       s += n.GETSensores(0).GETvalor();
       ADC0.setText(s);
  
  
   }
  
   public void UpdateNodeInformation(Nodes n)
   {
       String s = new String();
       s += n.GETSourceNodeID();
  
       //if(s.equals())
  
   }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    //SOME CODE OF LIGAÇÃO CLASS
    public class ligação 
    {
        protected PrincipalActivity cont;
      //Constructors
      public ligação(String ss,int Port,PrincipalActivity c){ s=ss; p=Port;cont = c; }
  
         public void read() 
     {
             while(flag)
             {
                ...
                cont.AddUpdateNodes(node, 0);
                ...
             }
  </code></pre>
  
  <p>Many thanks in advance</p>