SetText fromHtml. Now, our button has the desired icon (see Figure 19‑3).



Now, our button has the desired icon (see Figure 19‑3).

Figure 19‑3. The ImagesDemo sample application


XML: The Resource Way


In Chapter 18, we showed how you can package XML files as raw resources and get access to them for parsing and usage. There is another way of packaging static XML with your application: the XML resource.

Simply put the XML file in , and you can access it by on a Resources object, supplying it a resource ID of plus the base name of your XML file. So, in an activity, with an XML file of , you could call .

This returns an instance of the currently‑undocumented , found in the Java namespace. Documentation for this library can be found at the parser’s site[13]as of this writing.

An XML pull parser is event‑driven: you keep calling on the parser to get the next event, which could be , , , etc. On a event, you can access the tag’s name and attributes; a single event represents the concatenation of all text nodes that are direct children of this element. By looping, testing, and invoking per‑element logic, you parse the file.

To see this in action, let’s rewrite the Java code for the sample project to use an XML resource. This new project, , requires that you place the file from not in , but in . The layout stays the same, so all that needs replacing is the Java source:

Дата добавления: 2015-05-16; просмотров: 680;

Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми. - Хелпикс.Орг - 2014-2023 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.003 сек.