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

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

Интервал:

Закладка:

Сделать

Fortunately, Android also supports adding tabs dynamically at runtime.

Adding tabs dynamically at runtime works much like the compile-time tabs previously shown, except you use a different flavor of setContent(), one that takes a TabHost.TabContentFactoryinstance. This is just a callback that will be invoked — you provide an implementation of createTabContent()and use it to build and return the Let’s take a look at an example ( Fancy/DynamicTab).

First, here is some layout XML for an activity that sets up the tabs and defines one tab, containing a single button:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:paddingTop="62px">

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:text="A semi-random button"

/>

What we want to do is add new tabs whenever the button is clicked. That can be accomplished in just a few lines of code:

public classDynamicTabDemo extendsActivity {

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

finalTabHost tabs = (TabHost) findViewById(R.id.tabhost);

tabs. setup();

TabHost.TabSpec spec = tabs. newTabSpec(buttontab);

spec. setContent(R.id.buttontab);

spec. setIndicator(Button);

tabs. addTab(spec);

tabs. setCurrentTab(0);

Button btn = (Button)tabs. getCurrentView(). findViewById(R.id.buttontab);

btn. setOnClickListener( newView. OnClickListener() {

publicvoid onClick(View view) {

TabHost.TabSpec spec = tabs. newTabSpec(tag1);

spec. setContent( newTabHost. TabContentFactory() {

publicView createTabContent(String tag) {

return( new AnalogClock(DynamicTabDemo. this));

}

});

spec. setIndicator(Clock);

tabs. addTab(spec);

}

});

}

}

In our button’s setOnClickListener()callback, we create a TabHost.TabSpecobject and give it an anonymous TabHost.TabContentFactory. The factory, in turn, returns the Viewto be used for the tab — in this case, just an AnalogClock. The logic for constructing the tab’s View could be much more elaborate, such as using LayoutInflaterto construct a view from layout XML.

In Figure 10-7 you can see that initially, when the activity is launched, we just have the one tab whereas Figure 10-8 shows multiple tabs.

Figure 107 The DynamicTab application with the single initial tab Figure - фото 39

Figure 10-7. The DynamicTab application, with the single initial tab

Figure 108 The DynamicTab application with three dynamicallycreated tabs - фото 40

Figure 10-8. The DynamicTab application, with three dynamically-created tabs

Intents and Views

In the preceding examples, the contents of each tab were set to be a View, such as a Button. This is easy and straight-forward, but it is not the only option. You can also integrate another activity from your application via an Intent.

Intentsare ways of specifying something you want accomplished, then telling Android to go find something to accomplish it. Frequently, these are used to cause activities to spawn. For example, whenever you launch an application from the main Android application launcher, the launcher creates an Intent and has Android open up the activity associated with that Intent. This whole concept, and how activities can be placed in tabs, will be described in greater detail in Chapter 25.

Flipping Them Off

Sometimes, you want the overall effect of tabs (only some Views visibleat a time), but you do not want the actual UI implementation of tabs. Maybe the tabs take up too much screen space. Maybe you want to switch between perspectives based on a gesture or a device shake. Or maybe you just like being different.

The good news is that the guts of the view-flipping logic from tabs can be found in the ViewFlippercontainer, which can be used in other ways than the traditional tab.

ViewFlipperinherits from FrameLayout, just like we used to describe the innards of a TabWidget. However, initially, it just shows the first child view. It is up to you to arrange for the views to flip, either manually by user interaction, or automatically via a timer.

For example, here is a layout for a simple activity ( Fancy/Flipper1) using a Buttonand a ViewFlipper:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Flip Me!"

/>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="#FF00FF00"

android:text="This is the first panel"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="#FFFF0000"

android:text="This is the second panel"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textStyle="bold"

android:textColor="#FFFFFF00"

android:text="This is the third panel"

/>

Notice that the layout defines three child views for the ViewFlipper, each a TextViewwith a simple message. Of course, you could have very complicated child views, if you so chose.

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

Интервал:

Закладка:

Сделать

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

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


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

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

x