Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Table of contents

| 0 comments |
Table of Contents:
  1. Android Fundamentals - Jargon Explained
  2. Preliminary Step: Eclipse set up / Create Android Project
  3. Android Explicit Intent Example
  4. Android Implicit Intent Example
  5. Invoking Android Pre-packaged Applications
  6. Fetching a result from a called activity
  7. Android Notifications Example
  8. Android Local Service Example
  9. Android Service and Notification Combined Example
  10. Android Remote Service Example
  11. Android Content Provider Example
  12. Android Broadcast Receiver Example
  13. Android SQLite DB Example
  14. Shared Preferences on Android
  15. Google Maps on Android
  16. Location Manager on Android
  17. Simple List View
  18. Custom List View
  19. Android Threads and Handlers
  20. Http Connection Using Threads
  21. Date Time Picker Views
  22. Auto Complete Text View
  23. Spinner View
  24. Gallery View
  25. Image Switcher View
  26. Creating Android UI Programmatically
  27. Android UI - Inflate from XML (Dynamic UI Creation)
  28. ListView of Data from SQLiteDatabase
  29. TabLayout or Tabbed View
  30. Options Menu
  31. Context Menu
  32. New Contacts Content Provider
    Titbits
    1. Simulating an incoming call on the Emulator
    2. Obtain Google Maps API Key
    3. Simulate Location Change in Android Emulator
    4. Updating to Android SDK 2.1
    5. Delete / Remove Applications deployed on the Android Emulator
    6. Disable Chinese / Japanese Characters on Emulator Keyboard
    7. Android Eclipse link Error - New Project
    All Sample code at One place / Alternate Download site for Code
    https://sites.google.com/site/saigeethamn/home/android-tutorial-code-for-download
    Read More..

    Table layout

    | 0 comments |
    Organizing widgets in a table is a famous approach in HTML design where you construct a table of a number of rows and cells and distribute the controls over the cells to achieve a consistent look for your UI. Android provides a similar technique.


    In android you define the number of rows by your own and android determines the number of cells in each row according to the number of widgets in each row




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Submit"
    />


    You can define a table and add rows and views to it like this:
    TableLayout tl=new TableLayout(this);
    TableRow tr=new TableRow(this);
    Button btn=new Button(this);
    btn.setText("Hello");
    tr.addView(btn);
    tl.addView(tr);
    setContentView(tl);
    This example represents a row with three cells.

    A table cell can span multiple columns like this:




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Submit"
    />




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Cancel"
    />



    Also you can choose which column to put your widget by using android:layout_column property, you define the Zero-based index of the column where you want your widget to be.




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Submit"
    />




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Cancel"
    />



    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Help"
    android_layout_column="1"
    />



    Note: if you specify an index greater than the actual cells count, the widget won’t appear. For example in the previous example if android:layout_column had a value greater than 2 the widget wouldn’t appear.

    Table layout also allows you to put widgets directly under the <TableRow> tag to act as a separator between rows.


    These widgets will have their width set to fill_parent.




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Submit"
    />




    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Cancel"
    />



    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Help"
    android_layout_column="5"
    />

    <Button
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_text="Separator"
    />


    In table layout each column occupies space equal to the size of the largest widget in it. But you can set the width of any column to take the largest available space, just like setting the width to 100 % in HTML. This is done by setting the property android:stretchColumns to the index of the column, also you can set multiple columns by separating them with a comma.

    Look at the layout below:






    Now we gonna to add android:stretchColumns="0" to the table layout and see what it’s gonna look like:






    Column 0 occupied the largest available space.

    You can set this property from code like this
    TableLayout tl=new TableLayout(this);
    tl.setColumnStretchable(0, true);
    the setColumnStretchable(ColumnIndex, IsStretchable)method parameters are the column index and a Boolean value to indicate it is going to be stretched.

    Now if we have a column that have a large content. Android columns by default do not wrap their content. Look at this layout:






    See column zero occupies large space that column 1 is not visible.

    We can use android:shrinkColumns property to wrap content of a certain column or for multiple columns by assigning column numbers separeted by commas.

    When we use the property with column zero it will be like this:






    Its like using style=”white-space:wrap;” style in HTML
    You can set the property from code like this:
    TableLayout tl=new TableLayout(this);
    tl.setColumnShrinkable(0, true);
    The setColumnShrinkable(columnIndex, isShrinkable) method parameters are the column index and a Boolean to indicate it si going to be shrinked.

    Finally if you want to make some columns invisible you can use the property android:collapseColumns the same way we used the last two properties






    See that column zero is invisible.
    You can use this property from code like this:
    TableLayout tl=new TableLayout(this);
    tl.setColumnCollapsed(0, true);
    The property setColumnCollapsed(columnIndex, isCollapsed) parameters are the column index and a Boolean to indicate that it’s going to be collapsed

    This is just like using the style=”display:none;” in HTML

    Other functions can be called from code:
    TableLayout.setShrinkAllColumns(Boolean shrinkAllColumns) : shrinks all colums
    TableLayout.setStretchAllColumns(Boolean stretchAllColumns): stretches all columns
    Read More..