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

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

Интервал:

Закладка:

Сделать

menu. add(Menu.NONE, EDIT_ID, Menu.NONE, "Edit Prefs")

. setIcon(R.drawable.misc)

. setAlphabeticShortcut('e');

menu. add(Menu.NONE, CLOSE_ID, Menu.NONE, "Close")

. setIcon(R.drawable.eject)

. setAlphabeticShortcut('c');

return( super. onCreateOptionsMenu(menu));

}

@Override

publicboolean onOptionsItemSelected(MenuItem item) {

switch(item. getItemId()) {

caseEDIT_ID:

startActivity( new Intent( this, EditPreferences. class));

return( true);

caseCLOSE_ID:

finish();

return( true);

}

return( super. onOptionsItemSelected(item));

}

However, that is all that is needed, and it really is not that much code outside of the preferences XML. What you get for your effort is an Android-supplied preference UI, as shown in Figure 17-1.

Figure 171 The Simple projects preferences UI The checkbox can be directly - фото 56

Figure 17-1. The Simple project’s preferences UI

The checkbox can be directly checked or unchecked. To change the ringtone preference, just click on the entry in the preference list to bring up a selection dialog like the one in Figure 17-2.

Figure 172 Choosing a ringtone preference Note that there is no explicit - фото 57

Figure 17-2. Choosing a ringtone preference

Note that there is no explicit Save or Commit button or menu — changes are persisted as soon as they are made.

The SimplePrefsDemoactivity, beyond having the aforementioned menu, also displays the current preferences via a TableLayout:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:text="Checkbox:"

android:paddingRight="5px"

/>

/>

android:text="Ringtone:"

android:paddingRight="5px"

/>

/>

The fields for the table are found in onCreate():

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super. onCreate(savedInstanceState);

setContentView(R.layout.main);

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

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

}

The fields are updated on each onResume():

@Override

publicvoid onResume() {

super. onResume();

SharedPreferences prefs = PreferenceManager

. getDefaultSharedPreferences( this);

checkbox. setText( new Boolean(prefs

. getBoolean("checkbox", false)). toString());

ringtone. setText(prefs. getString("ringtone", ""));

}

This means the fields will be updated when the activity is opened and after the preferences activity is left (e.g., via the back button); see Figure 17-3.

Figure 173 The Simple projects list of saved preferences Adding a Wee Bit - фото 58

Figure 17-3. The Simple project’s list of saved preferences

Adding a Wee Bit o’ Structure

If you have a lot of preferences for users to set, having them all in one big list may become troublesome. Android’s preference framework gives you a few ways to impose a bit of structure on your bag of preferences, including categories and screens.

Categories are added via a PreferenceCategoryelement in your preference XML and are used to group together related preferences. Rather than have your preferences all as children of the root PreferenceScreen, you can put a few PreferenceCategoryelements in the PreferenceScreen, and then put your preferences in their appropriate categories. Visually, this adds a divider with the category title between groups of preferences.

If you have lots and lots of preferences — more than is convenient for users to scroll through — you can also put them on separate “screens” by introducing the PreferenceScreenelement.

Yes, that PreferenceScreenelement.

Any children of PreferenceScreengo on their own screen. If you nest PreferenceScreens, the parent screen displays the screen as a placeholder entry — tapping that entry brings up the child screen. For example, from the Prefs/Structuredsample project on the Apress Web site, here is a preference XML file that contains both PreferenceCategoryand nested PreferenceScreenelements:

xmlns:android="http://schemas.android.com/apk/res/android">

android:key="@string/checkbox"

android:title="Checkbox Preference"

android:summary="Check it on, check it off"

/>

android:key="@string/ringtone"

android:title="Ringtone Preference"

android:showDefault="true"

android:showSilent="true"

android:summary="Pick a tone, any tone"

/>

android:key="detail"

android:title="Detail Screen"

android:summary="Additional preferences held in another page">

android:key="@string/checkbox2"

android:title="Another Checkbox"

android:summary="On. Off. It really doesn't matter."

/>

The result, when you use this preference XML with your PreferenceActivityimplementation, is a categorized list of elements like those in Figure 17-4.

Figure 174 The Structured projects preference UI showing categories and a - фото 59

Figure 17-4. The Structured project’s preference UI, showing categories and a screen placeholder

And if you tap on the Detail Screen entry, you are taken to the child preference screen (Figure 17-5).

Figure 175 The child preference screen of the Structured projects preference - фото 60

Figure 17-5. The child preference screen of the Structured project’s preference UI

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

Интервал:

Закладка:

Сделать

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

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


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

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

x