{"id":7213,"date":"2014-05-28T02:20:14","date_gmt":"2014-05-28T02:20:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/28\/android-dynamic-tablelayout-not-appearing-collection-of-common-programming-errors\/"},"modified":"2014-05-28T02:20:14","modified_gmt":"2014-05-28T02:20:14","slug":"android-dynamic-tablelayout-not-appearing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/28\/android-dynamic-tablelayout-not-appearing-collection-of-common-programming-errors\/","title":{"rendered":"Android &#8211; Dynamic TableLayout not appearing-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to implement a HUD display to my cutsom keyboard. The HUD will contain pairs of key\/value. I need to programatically create a TableLayout and draw it on my canvas. In order to do this, I am overriding the keyboardview onDraw() method:<\/p>\n<pre><code>@Override\npublic void onDraw(Canvas canvas) {  \/\/ In the custom MyKeyboardView class\n    MyHUD hud = new MyHUD(getContext());\n    super.onDraw(canvas);\n    hud.tl.draw(canvas);    \/\/tl being the TableLayout to draw\n}\n<\/code><\/pre>\n<p>MyHUD class:<\/p>\n<pre><code>public class MyHUD {\n\n    public TableLayout tl;\n    private MyData mData;\n\n    public MyHUD(Context context) {\n\n      TableRow.LayoutParams trParams = new TableRow.LayoutParams(\n        TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);\n      TableLayout.LayoutParams tlParams = new TableLayout.LayoutParams(\n        TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);\n\n      tl = new TableLayout(context);\n      tl.setLayoutParams(tlParams);\n\n      for (int i = 0; i &lt; 10; i++) {\n\n        TableRow tr = new TableRow(context);\n        tr.setId(100+i);\n        tr.setLayoutParams(trParams);\n\n        TextView charTV = new TextView(context);\n        charTV.setId(200+i);\n        charTV.setText(\"Hello \" + i);\n        charTV.setTextColor(Color.RED);\n        \/\/charTV.setLayoutParams(trParams);\n        tr.addView(charTV);\n\n        TextView keyTV = new TextView(context);\n        keyTV.setId(300+i);\n        keyTV.setText(\"world \" + i);\n        keyTV.setTextColor(Color.CYAN);\n        \/\/keyTV.setLayoutParams(trParams);\n        tr.addView(keyTV);\n\n        tl.addView(tr, tlParams);   \n      }       \n   }\n}\n<\/code><\/pre>\n<p>(Note that currently there is no data fetching, just a &#8220;Hello world&#8221; for test purposes). I have commented out the TextView layouts, as seen on several other posts, but that doesn&#8217;t seem to be the problem.<\/p>\n<p>Alternative option:<\/p>\n<p>Instead of instanciating the TableLayout via a constructor, I have tried something like:<\/p>\n<pre><code>tl = (TableLayout) findViewById(R.id.my_hud);\n<\/code><\/pre>\n<p>Along with the following XML:<\/p>\n<pre><code>\n\n\n<\/code><\/pre>\n<p>The problem is that the findViewById method is undefined for my custom class.<\/p>\n<p>Any idea why it is not properly drawing the TableLayout?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to implement a HUD display to my cutsom keyboard. The HUD will contain pairs of key\/value. I need to programatically create a TableLayout and draw it on my canvas. In order to do this, I am overriding the keyboardview onDraw() method: @Override public void onDraw(Canvas canvas) { \/\/ In the custom MyKeyboardView [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7213","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7213"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7213\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}