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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

• A result code from the child activity calling setResult(). Typically this is RESULT_OKor RESULT_CANCELLED, though you can create your own return codes (pick a number starting with RESULT_FIRST_USER).

• An optional Stringcontaining some result data, possibly a URL to some internal or external resource — for example, an ACTION_PICK Intenttypically returns the selected bit of content via this data string.

• An optional Bundlecontaining additional information beyond the result code and data string.

To demonstrate launching a peer activity, take a peek at the Activities/Launchsample application in the Source Code section at http://apress.com. The XML layout is fairly straightforward: two fields for the latitude and longitude, plus a button:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:stretchColumns="1,2"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="2dip"

android:paddingRight="4dip"

android:text="Location:"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:cursorVisible="true"

android:editable="true"

android:singleLine="true"

android:layout_weight="1"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:cursorVisible="true"

android:editable="true"

android:singleLine="true"

android:layout_weight="1"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Show Me!"

/>

The button’s OnClickListenersimply takes the latitude and longitude, pours them into a geoscheme Uri, then starts the activity.

packagecom.commonsware.android.activities;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.net.Uri;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.EditText;

public classLaunchDemo extendsActivity {

privateEditText lat;

privateEditText lon;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.map);

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

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

btn. setOnClickListener( newView. OnClickListener() {

publicvoid onClick(View view) {

String _lat = lat. getText(). toString();

String _lon = lon. getText(). toString();

Uri uri=Uri. parse("geo:"+_lat+","+_lon);

startActivity( new Intent(Intent.ACTION_VIEW, uri));

}

});

}

}

The activity is not much to look at (Figure 24-1).

Figure 241 The LaunchDemo sample application with a location filled in If - фото 73

Figure 24-1. The LaunchDemo sample application, with a location filled in

If you fill in a location (e.g., 38.8891 latitude and -77.0492 longitude) and click the button, the resulting map is more interesting (Figure 24-2). Note that this is the built-in Android map activity — we did not create our own activity to display this map.

Figure 242 The map launched by LaunchDemo showing the Lincoln Memorial in - фото 74

Figure 24-2. The map launched by LaunchDemo, showing the Lincoln Memorial in Washington DC

In a Chapter 34, you will see how you can create maps in your own activities, in case you need greater control over how the map is displayed.

Tabbed Browsing, Sort Of

One of the main features of the modern desktop Web browser is tabbed browsing, where a single browser window can show several pages split across a series of tabs. On a mobile device this may not make a lot of sense, given that you lose screen real estate for the tabs themselves.

In this book, however, we do not let little things like sensibility stop us, so let me demonstrate a tabbed browser, using TabActivityand Intents.

As you may recall from Chapter 10, a tab can have either a Viewor an Activityas its content. If you want to use an Activityas the content of a tab, you provide an Intentthat will launch the desired Activity; Android’s tab-management framework will then pour the Activity’s user interface into the tab.

Your natural instinct might be to use an http:Urithe way we used a geo:Uriin the previous example:

Intent i = new Intent(Intent.ACTION_VIEW);

i. setData(Uri. parse("http://commonsware.com"));

That way, you could use the built-in Browser application and get all of the features that it offers.

Alas, this does not work. You cannot host other applications’ activities in your tabs — only your own activities, for security reasons.

So, we dust off our WebViewdemos from Chapter 13 and use those instead, repackaged as Activities/IntentTab.

Here is the source to the main activity, the one hosting the TabView:

public classIntentTabDemo extendsTabActivity {

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super. onCreate(savedInstanceState);

TabHost host = getTabHost();

host. addTab(host. newTabSpec("one"). setIndicator("CW")

. setContent( new Intent( this, CWBrowser. class)));

host. addTab(host. newTabSpec("two"). setIndicator("Android")

. setContent( new Intent( this, AndroidBrowser. class)));

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

Интервал:

Закладка:

Сделать

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

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


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

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

x