Displaying Data From Code

Understand how to set all the data from code and write the logic for the image with a back icon in this lesson.

Tools attributes

In the previous lesson, we defined test layout data inside the XML file, but this data will be dynamically set from code. If we leave things as they are right now, we will see the test data before the real data is loaded.

To avoid this situation, we can remove the test data, but this means that it will be hard to understand what data should be displayed without digging into code. There is a better way to handle this situation - tools attributes.

Tools attributes live in a special namespace: xmlns:tools="http://schemas.android.com/tools". It’s a set of attributes to enable design-time features. These attributes are automatically removed during the compilation process.

First, let’s add a tools namespace to the root layout.

Get hands-on with 1200+ tech skills courses.