Mark Murphy - Beginning Android

Здесь есть возможность читать онлайн «Mark Murphy - Beginning Android» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: New York, Год выпуска: 2009, ISBN: 2009, Издательство: Apress, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Beginning Android: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Beginning Android»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Master Android from first principles and begin the journey toward your own successful Android applications!
Dear Reader,
First, welcome to the world of Android! We’re entering a new era of mobile application development, one marked by open platforms and open source, to take ‘walled gardens’ and make them green houses for any and all to participate in. Android is relatively easy for developers, and I believe that this innovation will help generate a large ecosystem of developers and consumers within a very short time. This means that budding developers such as yourself will have many opportunities to design and build your own applications and you’ll have a huge and hungry customer base.
Second, welcome to the book! Its purpose is to start you on your way with building Android applications, and to help you master the learning curve. Android is already a rich framework, comparable in many ways to the richness Android of desktop Java environments. This means that there is a lot of cool stuff for you to pick up along your journey in order to create the slickest, most useful apps Android you can imagine.
The source code for the code samples in this book is all available from the Apress site, so you can stay as hands-on and practical as you like while I introduce you to the core of Android, and invite you to experiment with the various classes and APIs we’ll be looking at. By the time you’ve finished this book, you’ll be creating your own Android applications and asking yourself what your next great application will be…!
Enjoy! Mark Murphy

Beginning Android — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Beginning Android», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/icon"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

Next, we need to put an image file in res/drawablewith a base name of icon. In this case, we use a 32×32 PNG file from the Nuvola [16] http://en.wikipedia.org/wiki/Nuvola icon set. Finally, we twiddle the Java source, replacing our Buttonwith an ImageButton:

packagecom.commonsware.android.resources;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.text.TextUtils;

importandroid.text.Html;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.ImageButton;

importandroid.widget.EditText;

importandroid.widget.TextView;

public classImagesDemo extendsActivity {

EditText name;

TextView result;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

name = (EditText) findViewById(R.id.name);

result = (TextView) findViewById(R.id.result);

ImageButton btn = (ImageButton) findViewById(R.id.format);

btn. setOnClickListener( newButton. OnClickListener() {

publicvoid onClick(View v) {

applyFormat();

}

});

}

privatevoid applyFormat() {

String format = getString(R.string.funky_format);

String simpleResult = String. format(format,

TextUtils. htmlEncode(name. getText(). toString()));

result. setText(Html. fromHtml(simpleResult));

}

}

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

Figure 193 The ImagesDemo sample application XML The Resource Way In - фото 67

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 res/xml/, and you can access it by getXml()on a Resources object, supplying it a resource ID of R.xml.plus the base name of your XML file. So, in an activity, with an XML file of words.xml, you could call getResources().getXml(R.xml.words).

This returns an instance of the currently-undocumented XmlPullParser, found in the org.xmlpull.v1Java namespace. Documentation for this library can be found at the parser’s site [17] http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/package-summary.html as of this writing.

An XML pull parser is event-driven: you keep calling next()on the parser to get the next event, which could be START_TAG, END_TAG, END_DOCUMENT, etc. On a START_TAGevent, you can access the tag’s name and attributes; a single TEXTevent 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 Files/Staticsample project to use an XML resource. This new project, Resources/XML, requires that you place the words.xmlfile from Staticnot in res/raw/, but in res/xml/. The layout stays the same, so all that needs replacing is the Java source:

packagecom.commonsware.android.resources;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.app.ListActivity;

importandroid.view.View;

importandroid.widget.AdapterView;

importandroid.widget.ArrayAdapter;

importandroid.widget.ListView;

importandroid.widget.TextView;

importandroid.widget.Toast;

importjava.io.InputStream;

importjava.util.ArrayList;

importorg.xmlpull.v1.XmlPullParser;

importorg.xmlpull.v1.XmlPullParserException;

public classXMLResourceDemo extendsListActivity {

TextView selection;

ArrayList items = newArrayList();

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

selection = (TextView) findViewById(R.id.selection);

try{

XmlPullParser xpp = getResources(). getXml(R.xml.words);

while(xpp. getEventType()!=XmlPullParser.END_DOCUMENT) {

if(xpp. getEventType()==XmlPullParser.START_TAG) {

if(xpp. getName(). equals("word")) {

items. add(xpp. getAttributeValue(0));

}

}

xpp. next();

}

} catch(Throwable t) {

Toast

. makeText( this, "Request failed: " + t. toString(), 4000). show();

}

setListAdapter( newArrayAdapter( this,

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Beginning Android»

Представляем Вашему вниманию похожие книги на «Beginning Android» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Beginning Android»

Обсуждение, отзывы о книге «Beginning Android» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x