title: Create a Custom ImageButton Class with FrameLayout and TextView
body: <p>I am a newbie, so, any help is appreciated. I read a lot of posts here at StackOverflow and also I searched for my doubt in Google, but it's hard to find a good answer.</p>
  
  <p>Here is what I am trying to do:</p>
  
  <pre><code>    &lt;FrameLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1"&gt;    
      &lt;ImageButton 
          android:background="@layout/roundcorners" 
          android:id="@+id/hug" 
          android:scaleType="centerInside"
          android:cropToPadding="false"
          android:paddingLeft="5dp"
          android:paddingRight="5dp"
          android:paddingBottom="10dip"
          android:layout_height="fill_parent" 
          android:layout_width="fill_parent"
          android:src="@drawable/hug"&gt;
      &lt;/ImageButton&gt;
      &lt;TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="bottom|center"
          android:textColor="#000000"
          android:textSize="15dip"
          android:textStyle="bold"
          android:paddingBottom="5dip"
          android:clickable="true" 
          android:text="Hug"&gt;
      &lt;/TextView&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>Above you guys can see the XML version of what I need.</strong></p>
  
  <p>The point is... I will have many of these FrameLayouts at run time. Every information to fill out the buttons will come from a database.</p>
  
  <p>So, I need to create a Java Class where I can use a loop through all the registers from my database and instantiate a new FrameLayout Class (this class must have an ImageButton and a TextView as you can see from above XML) and just pass parameters, like this:</p>
  
  <pre><code>for (int i = 0; i &lt; mArray.length; i++) {
          button = new MyNewImageButton(name, src, text);
  }
  </code></pre>
  
  <p>The above is just to simplify. What I mean is that I will pass parameters from my database when creating an Instance of this class that I am planning to create. Of course, every single button created will be added to the layout.</p>
  
  <p><strong>So... my question is: I know how to do this using XML, but I am REALLY having a hard time to create a class to do this.</strong></p>
  
  <p><strong>Any thoughts? Any help is appreciated.</strong></p>
  
  <p>P.S.: Sorry if I made any mistake in my English, ok? I am a Brazilian. Someday my English will be flawless! Sorry if this question was already answered. </p>
  
  <hr>
  
  <p>sorry to answer my own question to make another question. I tried to use the comments but there's a limitation in the number of characters, so, I am really sorry. </p>
  
  <p>Hey guys and @blessenm. Well... I tried to use inflater and I came up with the following code:  </p>
  
  <pre><code>    super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
  
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
              WindowManager.LayoutParams.FLAG_FULLSCREEN);  
      // ******************************************* 
      setContentView(R.layout.main);      
  
  
      //this is my main screen
      //it's a linearlayout vertical orientation
      ViewGroup parent = (ViewGroup) findViewById(R.id.tela_principal);
  
      //these two new LinearLayouts will be one above the other, 
      //just like two lines
      LinearLayout l1 = new LinearLayout(this);
      LinearLayout l2 = new LinearLayout(this);
  
      //inside of each linearlayout I set the orientation to horizontal
      //so, everytime a picture is inflated from xml, it will fill in one
      //linearlayout
      l1.setOrientation(LinearLayout.HORIZONTAL);
      l2.setOrientation(LinearLayout.HORIZONTAL);
  
      //setting linearlayout parameters, so they fill the whole screen
      l1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
      l2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  
  
      //the first two inflated xml imagebuttons I add to LinearView1
      view = LayoutInflater.from(getBaseContext()).inflate(R.layout.figurabotao,
              l1, true);
      view = LayoutInflater.from(getBaseContext()).inflate(R.layout.figurabotao,
              l1, true);
  
      //the next two inflated xml imagebuttons I add to LinearView2
      view = LayoutInflater.from(getBaseContext()).inflate(R.layout.figurabotao,
              l2, true);
      view = LayoutInflater.from(getBaseContext()).inflate(R.layout.figurabotao,
              l2, true);
  
      //after the above, we should have a grid 2X2
  
  
      //after linearlayouts are filled, I add them to the main screen
      parent.addView(l1, new LinearLayout.LayoutParams(0, 0, 1));
      parent.addView(l2, new LinearLayout.LayoutParams(0, 0, 1));
  </code></pre>
  
  <p>However this is not working. In the errorlog I get the following message:</p>
  
  <p>"Unhandled event loop exception".</p>
  
  <p>Any ideas about what I am doing wrong?</p>
  
  <p>Thanks!</p>