"Maximizing TableView Cell Height to Utilize the Entire Screen

After reading the tutorial on Appcelerator: Using JSON to Build a Twitter Client, I decided to create my own application to communicate with a Jetty server running some Spring code. My application makes a GET HTTP request that returns contacts in JSON format, which I then use to populate a TableView.

Everything seems to be working fine, except for the fact that each row in my TableView is taking up the entire screen. This means that I can scroll vertically to see all the data, but I am struggling to figure out why the styling is causing the cells to occupy the full screen. Since my CSS skills are lacking, any guidance or assistance would be highly appreciated. Thank you!

Below is the JavaScript file responsible for loading the TableView:

// Define variable "win" as current window
var win = Titanium.UI.currentWindow;

// Function to load contacts
function loadContacts() {

    // Empty array "rowData" to store table view cells
    var rowData = [];

    // Create HTTP client
    var loader = Titanium.Network.createHTTPClient();
    // Set HTTP request method and URL
    loader.setRequestHeader("Accept", "application/json");
    loader.open("GET", "http://localhost:8080/contactsample/contacts");
    // Execute when data is ready to process
    loader.onload = function(){

        Ti.API.debug("JSON Data: " + this.responseText);

        // Parse JSON data
        var contacts = JSON.parse(this.responseText);

        for(var i=0; i < contacts.length; i++) {

            var id = contacts[i].id;
            Ti.API.info("JSON Data, Row[" + i + "], ID: " + contacts[i].id);
            var name = contacts[i].name;
            Ti.API.info("JSON Data, Row[" + i + "], Name: " + contacts[i].name);
            var phone = contacts[i].phone;
            Ti.API.info("JSON Data, Row[" + i + "], Phone: " + contacts[i].phone);
            var address = contacts[i].address;
            Ti.API.info("JSON Data, Row[" + i + "], Address: " + contacts[i].address);

            // Create row
            var row = Titanium.UI.createTableViewRow({ height:'auto' });

            // Create row's view
            var contactView = Titanium.UI.createView({ height:'auto', layout:'vertical', top:5, right:5, bottom:5, left:5 });
            var nameLbl = Titanium.UI.createLabel({
                text:name,
                left:5,
                height:24,
                width:236,
                textAlign:'left',
                color:'#444444',
                font:{
                    fontFamily:'Trebuchet MS', fontSize:16, fontWeight:'bold'
                }
            });
            var phoneLbl = Titanium.UI.createLabel({
                text: phone,
                top:0,
                bottom:2,
                height:'auto',
                width:236,
                textAlign:'right',
                font:{ fontSize:14}
            });
            var addressLbl = Titanium.UI.createLabel({
                text: address,
                top:0,
                bottom:2,
                height:'auto',
                width:236,
                textAlign:'right',
                font:{ fontSize:14}
            });
            contactView.add(nameLbl);
            contactView.add(phoneLbl);
            contactView.add(addressLbl);

            row.add(contactView);
            row.className = "item" + i;

            rowData.push(row);
        }

        Ti.API.info("RowData: " + rowData);

        // Create table view
        var tableView = Titanium.UI.createTableView( { data: rowData });
        win.add(tableView);
    };

    // Send request
    loader.send();

}

// Fetch contacts
loadContacts();

Attached are screenshots demonstrating the issue I'm encountering. Despite tweaking the pixel values for top, bottom, right, and left, I haven't been able to find a solution. Any help would be greatly valued. Thank you!

Answer №1

After not receiving a response here, I decided to post my question on the Titanium Appcelerator Q&A site. It turns out that the tutorials I relied on to learn Titanium were outdated. The auto tag is no longer supported and it is now recommended to use constants provided in the Titanium API. Many thanks to the helpful responses on my previous thread.

The answer that helped me solve my issues:

auto has been deprecated. Instead, you should use FILL or SIZE.

In your case, when creating a contactView, set its height to Ti.UI.SIZE. This way, the view will adjust its size to fit its contents.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Angular tutorial for the "Tour of Heroes" is experiencing issues with aligning the heroes' list properly

I am currently working on the Angular tour of heroes tutorial. However, I am facing an issue when trying to display the list of heroes as it appears like this: https://i.sstatic.net/AGnzJ.png It is strange because even though the CSS/HTML/TS code from the ...

Finishing a division by both clicking outside of it and pressing a button

I am currently working on setting up a dropdown menu that can be closed both by clicking outside the opened div and by clicking the button or image that opens the div. Image with onclick function: <img onclick="hide()" id="menu" src="...."> Th ...

Javascript functions correctly when the HTML file is opened locally, however, it encounters issues when accessed through an http-server

My HTML file includes an embedded web widget from tradingview.com with the following code: <!-- TradingView Widget BEGIN --> <span id="tradingview-copyright"><a ref="nofollow noopener" target="_blank" href="http://www.tradingview.com" style ...

What does the client perceive or not perceive? Node.js, JavaScript, MySQL

For a university project, I am tasked with creating a web application that is compatible with both desktop browsers and mobile devices. The technologies I will be using include HTML, CSS, JavaScript, Node.js, and MySQL. I have recently familiarized myself ...

What causes the CSS class and jQuery to become unresponsive when rapidly moving the cursor over a specific selector while utilizing .hover(), .addClass() and .removeClass()?

After creating a customized h1 element, I implemented a feature where a class is added and removed from it with a smooth transition of 300ms when the mouse hovers over and off its parent DIV #logo. This was achieved using jQuery's .hover() method alon ...

Use a CSS rule only if the element is not nested by using the :not selector

Could use some assistance with this coding issue: .element { border: 1px solid red; display: block; } I want to exclude this rule when .element is a descendant of .no-border using the :not pseudo-selector. For example: <div class="element">I ...

Placing an exit button beside an image for easy navigation

Here is a snippet of my code: <style type="text/css"> .containerdiv { position:relative;width:100%;display:inline-block;} .image1 { position: absolute; top: 20px; left: 10px; } </style> <div class="containerdiv"> <ima ...

Centered background position for CSS h2

Hey there! I've got this CSS code for my H2 heading: .rightBox h2 { background: url(images/lineh2.png) 0px 0px no-repeat; border-top: 1px solid #e4e4e4; margin-bottom: 15px; font-size: 22px; font-weight: 100; font-family: "Seg ...

Learn how to cycle through three different texts that appear in the same spot using smooth transitions

I am working with three different rows that contain the Typography component. My goal is to display the first row, followed by the second, then the third, and back to the first one in a continuous loop. All three rows should be shown in the same location, ...

Troubleshooting CSS compatibility issues in Firefox browser (or HTML rendering as plain text)

In a unique web page comparing two photos, the clicked one changes, but there's an issue in Firefox where HTML displays as text and links don't work. CODE:- * { box-sizing: border-box; } html { height: 100%; } body { height: 100%; mar ...

Is there a way to prevent this from moving and have it only load below?

Is there a way to prevent an input box from altering the size of an HTML <li> element when it is revealed beneath item 2? Additionally, how can one ensure that the input box opens directly below item 2 without affecting the layout? Lastly, what adj ...

Exploring design techniques in React Native

I am currently part of a team working on a react native project with multiple contributors. My goal is to find an effective way to segregate the styling tasks from coding, allowing UI developers to work independently without relying on code developers. In ...

Update the bootstrap navigation bar

I'm currently using bootstrap to construct my website. The navbar I have is quite typical with menu options, but I am aiming to modify the CSS in order to achieve a design similar to the image provided below (this design should be responsive and funct ...

Hide a div when multiple classes are filtered using jQuery

I have several divs with the class .item. When the user clicks on the Classfilter submit button, all .item elements that also have at least one class from the dateClasses array (for example ['28.09.2015', '29.09.2015']) should be hidden ...

Issues with image sizing on mobile devices

After finalizing my header design, I encountered an issue with the mobile version of the website. The images in the header are not responsive and do not adapt well to different screen sizes. I need assistance converting the header design into functional co ...

What is the best way to create a flexible grid that automatically adjusts to either two columns or one column depending on the width of the

My challenge lies in arranging items into two columns or one, with a specific layout for mobile devices. The order of the items changes between the two column and single column layouts. The number and size of items vary dynamically. For example, in a tw ...

Is there a way to position the table to the right of the registration text boxes?

https://i.sstatic.net/Fh9Bk.jpg Is it possible to position the table using <div> elements? ...

The CSS transition duration is not being applied properly on the initial transition effect

Looking to create a dynamic set of sliding divs that can be triggered with the press of a button. Each div will contain a thumbnail image and accompanying text. The goal is to enable the user to navigate through the content by clicking the left or right bu ...

"Choose" with the icon permanently attached

I am looking to customize a select element to choose a month. I want the dropdown list to display only the name of the months (e.g., January, February). However, in the selected value box of the select element, I would like to show a FontAwesome icon repre ...

Switch the visibility of an HTML input styled as a "spinner"

I have managed to create a CSS-based method for toggling the visibility of span or input elements depending on whether a radio button is checked. I got inspired by this insightful question on Stack Overflow. However, I encountered an issue where this togg ...