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

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

Интервал:

Закладка:

Сделать

To find out when a context-menu choice was selected, implement onContextItemSelected()on the activity. Note that you get only the MenuIteminstance that was chosen in this callback. As a result, if your activity has two or more context menus, you may want to ensure they have unique menu-item identifiers for all their choices so you can tell them apart in this callback. Also, you can call getMenuInfo()on the MenuItemto get the ContextMenu.ContextMenuInfoyou received in onCreateContextMenu(). Otherwise, this callback behaves the same as onOptionsItemSelected(), described in the previous section.

Taking a Peek

In the sample project Menus/Menusat http://apress.com/, you will find an amended version of the ListViewsample ( List) with an associated menu. Since the menus are defined in Java code, the XML layout need not change and is not reprinted here.

However, the Java code has a few new behaviors, as shown here:

public classMenuDemo extendsListActivity {

TextView selection;

String[] items={"lorem", "ipsum", "dolor", "sit", "amet",

"consectetuer", "adipiscing", "elit", "morbi", "vel",

"ligula", "vitae", "arcu", "aliquet", "mollis",

"etiam", "vel", "erat", "placerat", "ante",

"porttitor", "sodales", "pellentesque", "augue", "purus"};

public static finalint EIGHT_ID = Menu.FIRST+1;

public static finalint SIXTEEN_ID = Menu.FIRST+2;

public static finalint TWENTY_FOUR_ID = Menu.FIRST+3;

public static finalint TWO_ID = Menu.FIRST+4;

public static finalint THIRTY_TWO_ID = Menu.FIRST+5;

public static finalint FORTY_ID = Menu.FIRST+6;

public static finalint ONE_ID = Menu.FIRST+7;

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

setListAdapter( newArrayAdapter( this,

android.R.layout.simple_list_item_1, items));

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

registerForContextMenu( getListView());

}

publicvoid onListItemClick(ListView parent, View v,

int position, long id) {

selection. setText(items[position]);

}

@Override

publicvoid onCreateContextMenu(ContextMenu menu, View v,

ContextMenu.ContextMenuInfo menuInfo) {

populateMenu(menu);

}

@Override

publicboolean onCreateOptionsMenu(Menu menu) {

populateMenu(menu);

return( super. onCreateOptionsMenu(menu));

}

@Override

publicboolean onOptionsItemSelected(MenuItem item) {

return( applyMenuChoice(item) ||

super. onOptionsItemSelected(item));

}

@Override

publicboolean onContextItemSelected(MenuItem item) {

return( applyMenuChoice(item) ||

super. onContextItemSelected(item));

}

privatevoid populateMenu(Menu menu) {

menu. add(Menu.NONE, ONE_ID, Menu.NONE, "1 Pixel");

menu. add(Menu.NONE, TWO_ID, Menu.NONE, "2 Pixels");

menu. add(Menu.NONE, EIGHT_ID, Menu.NONE, "8 Pixels");

menu. add(Menu.NONE, SIXTEEN_ID, Menu.NONE, "16 Pixels");

menu. add(Menu.NONE, TWENTY_FOUR_ID, Menu.NONE, "24 Pixels");

menu. add(Menu.NONE, THIRTY_TWO_ID, Menu.NONE, "32 Pixels");

menu. add(Menu.NONE, FORTY_ID, Menu.NONE, "40 Pixels");

}

privateboolean applyMenuChoice(MenuItem item) {

switch(item. getItemId()) {

caseONE_ID:

getListView(). setDividerHeight(1);

return( true);

caseEIGHT_ID:

getListView(). setDividerHeight(8);

return( true);

caseSIXTEEN_ID:

getListView(). setDividerHeight(16);

return( true);

caseTWENTY_FOUR_ID:

getListView(). setDividerHeight(24);

return( true);

caseTWO_ID:

getListView(). setDividerHeight(2);

return( true);

caseTHIRTY_TWO_ID:

getListView(). setDividerHeight(32);

return( true);

caseFORTY_ID:

getListView(). setDividerHeight(40);

return( true);

}

return( false);

}

}

In onCreate(), we register our list widget as having a context menu, which we fill in via our populateMenu()private method, by way of onCreateContextMenu(). We also implement the onCreateOptionsMenu()callback, indicating that our activity also has an options menu. Once again, we delegate to populateMenu()to fill in the menu.

Our implementations of onOptionsItemSelected()(for options-menu selections) and onContextItemSelected()(for context-menu selections) both delegate to a private applyMenuChoice()method, plus chaining upwards to the superclass if none of our menu choices was the one selected by the user.

In populateMenu()we add seven menu choices, each with a unique identifier. Being lazy, we eschew the icons.

In applyMenuChoice()we see if any of our menu choices were chosen; if so, we set the list’s divider size to be the user-selected width.

Initially the activity looks the same in the emulator as it did for ListDemo(see Figure 11-1).

Figure 111 The MenuDemo sample application as initially launched But if you - фото 44

Figure 11-1. The MenuDemo sample application, as initially launched

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

Интервал:

Закладка:

Сделать

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

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


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

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

x