<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; field</title>
	<atom:link href="http://devblog.blackberry.com/tag/field/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 17:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; field</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>How to use Table View layout</title>
		<link>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/</link>
		<comments>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 22:50:22 +0000</pubDate>
		<dc:creator>Shiladitya S.</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Java Development]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[Manager]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://blackberrydev.edstaging.com/?p=553</guid>
		<description><![CDATA[Every layout is unique and highly dependent upon the application using it. However, the basic building block for any complex layout is a cell. Each cell can define its space requirements or share with adjacent cells. If we try to visualize this arrangement it will look much like a table. With TableLayoutManager (full sample code [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=553&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Every layout is unique and highly dependent upon the application using it. However, the basic building block for any complex layout is a cell. Each cell can define its space requirements or share with adjacent cells. If we try to visualize this arrangement it will look much like a table. With TableLayoutManager (<a href="http://www.blackberry.com/knowledgecenterpublic/livelink.exe/How_To_-_Create_a_rich_UI_layout_with_TableLayoutManager.html?func=doc.Fetch&amp;nodeId=1906675&amp;docTitle=How+To+%2D+Create+a+rich+UI+layout+with+TableLayoutManager&amp;vernum=2" target="_self">full sample code here</a>), which can handle fixed or relative cell sizes and allow embedding tables, developers can build almost any layout they want very easily. I am not going to focus today on how to build a layout manager, as there are ample <a href="http://www.blackberry.com/developers" target="_self">BlackBerry® Developer Zone</a>resources on this topic. Instead, I will explore the possibilities of how TableLayoutManager can be used. TableLayoutManager has two constructors:</p>
<p><code>public TableLayoutManager(int columnStyles[], long style)</code></p>
<p><code> </code></p>
<p><code>public TableLayoutManager(int columnStyles[], int columnWidths[], int<br />
horizontalPadding, long style )<span id="more-553"></span><br />
</code></p>
<p><em>columnStyles[] </em>defines the styles for all columns, and the number of this array refers to the number of columns desired in a given row. The different column styles to choose from are listed below:<br />
USE_PREFERRED_SIZE   – Allows the field to use up all the space it needs.<br />
USE_PREFERRED_WIDTH_WITH_MAXIMUM – Allows the field to use up as much space as it needs UP TO a preset maximum. You can specify the maximum for each field by passing in the width in the columnWidths variable.<br />
SPLIT_REMAINING_WIDTH – Columns will use up the remaining width evenly.<br />
FIXED_WIDTH – Sets columns to a fixed width.</p>
<p>The SPLIT_REMAINING_WIDTH style can be thought of as the “this column will utilize all the remaining width of the table” style. So if TableLayoutManager has a column defined as SPLIT_REMAINING_WIDTH in conjunction with Manager.USE_ALL_WIDTH, the column will fill the remaining space. If there are multiple columns defined as SPLIT_REMAINING_WIDTH, they will evenly share that remaining width.</p>
<p><em>style –</em> is the manager style. You can just choose from Manager. HORIZONTAL_SCROLL, Manager.xxxx.</p>
<p><em>columnWidths –</em> if you choose you can specify widths to be used for each field for force particular columns size.</p>
<p><em>horizontalPadding –</em> you can also specify horizontal padding between columns .</p>
<p>As you can see above, it’s pretty easy to define the desired amount of columns. Based on number of fields added to the layout, TableLayoutManager will automatically align them in separate rows to keep the desired number of columns. This can often be a helpful feature, as developers won’t need to know the number of rows their table may have at construction time.</p>
<p>Now let’s explore some views that are possible with TableLayoutManager.</p>
<p><strong>Example 1: Say you are building your next great application that requires cover art to be displayed as a grid like view.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-15.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3140" /></p>
<p><strong><span style="font-weight:normal;">This view has five columns, each of which is a BitmapField and each field will accept focus  . This table can be constructed very easily with TableLayoutManager. Here is a code sample of how I constructed the table:</span></strong></p>
<p><code>TableLayoutManager colFMgr = new TableLayoutManager(new int[]<br />
{<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE<br />
}, Manager.HORIZONTAL_SCROLL);</code></p>
<p><code> </code></p>
<p><code>for(int i= 0;i &lt; images.length;i++) {<br />
colFMgr.add(new BitmapField(images[i],Field.FOCUSABLE));<br />
}<br />
add(colFMgr );</code></p>
<p>If you want a little more control on bitmap sizes and how the layout manager uses each cell size you can use the other constructor to pass in widths for each column.</p>
<p><strong>Example 2: Now say I wanted some text below each image but did not want the text to take primary focus.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-16.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3141" /></p>
<p>As you can see, it’s the same structure as Example 1, but for every five BitmapFields, I would have to add five Label fields and disable focus on the Labels. TableLayoutManager will take care of the layout and ordering.</p>
<p><strong>Example 3: Now consider using a table view where the left column contains an image and right columns contain some textual description with a ‘more’ link.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3143" /></p>
<p>Conceptually, the per-row view in wireframe would be an outer table with 2 columns:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3143" /></p>
<p>And an inner table with two columns to host some textual description:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-18.jpg?w=306&#038;h=103" alt="" title="How to use Table View layout" width="306" height="103" class="aligncenter size-full wp-image-3144" /></p>
<p>The inner table is inserted within the COL 1 of the outer table to get our desired view for a given row. Note that the space alignments are configurable based on the style you choose on the layout manager.</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-19.jpg?w=212&#038;h=105" alt="" title="How to use Table View layout" width="212" height="105" class="aligncenter size-full wp-image-3146" /></p>
<p>Now that we have constructed each row, you can keep adding COL 1(flower art bitmap) and COL 2 (inner table) and it will take the form as shown in the Example 3 screen shot. All this translates in very little code using TableLayoutManager:</p>
<p><code>TableLayoutManager outerTable = newTableLayoutManager(new int[]<br />
{<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.SPLIT_REMAINING_WIDTH<br />
},0);</code></p>
<p>For constructing the inner table:</p>
<p><code>TableLayoutManager innerTable = new TableLayoutManager(new int[]<br />
{<br />
TableLayoutManager. USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE<br />
}, Manager.USE_ALL_WIDTH);</code></p>
<p>In the second case, USE_ALL_WIDTH causes the table to fill the maximum width space. The first USE_PREFERRED_WIDTH will allow COL 1 to take up the minimum necessary amount of space, and COL 2 will automatically fill to fit. If you want COL 2 to use the minimum size, set COL 1 to SPLIT_REMAINING_WIDTH.</p>
<p>Here’s how to add the fields to the inner table:<br />
<code>innerTable.add(titleField);<br />
innerTable.add(titleField1);<br />
innerTable.add(descriptionField);<br />
innerTable.add(descriptionFieldLink);<br />
innerTable.add(ratingField);<br />
innerTable.add(ratingFieldImage);</code></p>
<p>And how to add a bitmap field to the outer table and add the inner table.<br />
<code>outerTable.add(Bitmap.getBitmapResource("image1.png")));<br />
outerTable.add(innerTable);</code></p>
<p>To add more rows to this table, keep adding bitmaps and inner tables to the outer table. And don’t forget to add the outer table to the Screen!<br />
<code>super.add(colFieldMgrForRow);</code></p>
<p>This is not the only way to build a layout like this. For example, for each row I can use a horizontal layout manager (hfm) with two columns. The second column for this hfm would need a vertical field manager (vfm), for which I need three hfm for each row of text (title, description, rating etc). So really there is no one size fits all for layout management. It’s simply a matter of picking the right one that works for your application.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/553/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=553&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/849ad61a03a581789c41b1c854ef9bf3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shiladitya S.</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-15.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-16.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-18.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-19.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>
	</item>
	</channel>
</rss>
