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

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

Интервал:

Закладка:

Сделать

return(guts);

}

void setGuts(View guts) {

this.guts = guts;

}

}

With all that in place, RateListViewis comparatively simple:

public classRateListView extendsListView {

public RateListView(Context context) {

super(context);

}

public RateListView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public RateListView(Context context, AttributeSet attrs,

int defStyle) {

super(context, attrs, defStyle);

}

publicvoid setAdapter(ListAdapter adapter) {

super. setAdapter( new RateableWrapper( getContext(), adapter));

}

}

We simply subclass ListViewand override setAdapter()so we can wrap the supplied ListAdapterin our own RateableWrapper.

Visually, the results are similar to the RateListDemo, albeit without top-rated words appearing in all caps (see Figure 9-5).

Figure 95 The RateListViewDemo sample application The difference is in - фото 32

Figure 9-5. The RateListViewDemo sample application

The difference is in reusability. We could package RateListViewin its own JAR and plop it into any Android project where we need it. So while RateListViewis somewhat complicated to write, we have to write it only once, and the rest of the application code is blissfully simple.

Of course, this RateListViewcould use some more features, such as programmatically changing states (updating both the float[]and the actual RatingBaritself), allowing other application logic to be invoked when a RatingBarstate is toggled (via some sort of callback), etc.

CHAPTER 10

Employing Fancy Widgets and Containers

The widgets and containers covered to date are not only found in many GUI toolkits (in one form or fashion), but also are widely used in building GUI applications, whether Web-based, desktop, or mobile. The widgets and containers in this chapter are a little less widely used, though you will likely find many to be quite useful.

Pick and Choose

With limited-input devices like phones, having widgets and dialogs that are aware of the type of stuff somebody is supposed to be entering is very helpful. It minimizes keystrokes and screen taps, plus reduces the chance of making some sort of error (e.g., entering a letter someplace where only numbers are expected).

As previously shown, EditTexthas content-aware flavors for entering in numbers, phone numbers, etc. Android also supports widgets ( DatePicker, TimePicker) and dialogs ( DatePickerDialog, TimePickerDialog) for helping users enter dates and times.

The DatePickerand DatePickerDialogallow you to set the starting date for the selection, in the form of a year, month, and day of month value. Note that the month runs from 0 for January through 11 for December. Most importantly, each let you provide a callback object ( OnDateChangedListeneror OnDateSetListener) where you are informed of a new date selected by the user. It is up to you to store that date someplace, particularly if you are using the dialog, since there is no other way for you to get at the chosen date later on.

Similarly, TimePickerand TimePickerDialoglet you:

• set the initial time the user can adjust, in the form of an hour (0 through 23) and a minute (0 through 59)

• indicate if the selection should be in 12-hour mode with an AM/PM toggle, or in 24-hour mode (what in the US is thought of as “military time” and in the rest of the world is thought of as “the way times are supposed to be”)

• provide a callback object ( OnTimeChangedListeneror OnTimeSetListener) to be notified of when the user has chosen a new time, which is supplied to you in the form of an hour and minute

The Fancy/Chronosample project, found along with all other code samples in this chapter in the Source Code area of http://apress.com, shows a trivial layout containing a label and two buttons — the buttons will pop up the dialog flavors of the date and time pickers:

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

android:orientation="vertical"

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="wrap_content"

android:text="Set the Date"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Set the Time"

/>

The more interesting stuff comes in the Java source:

public classChronoDemo extendsActivity {

DateFormat fmtDateAndTime = DateFormat. getDateTimeInstance();

TextView dateAndTimeLabel;

Calendar dateAndTime = Calendar. getInstance();

DatePickerDialog.OnDateSetListener d =

newDatePickerDialog. OnDateSetListener() {

publicvoid onDateSet(DatePicker view, int year, int monthOfYear,

int dayOfMonth) {

dateAndTime. set(Calendar.YEAR, year);

dateAndTime. set(Calendar.MONTH, monthOfYear);

dateAndTime. set(Calendar.DAY_OF_MONTH, dayOfMonth);

updateLabel();

}

};

TimePickerDialog.OnTimeSetListener t =

newTimePickerDialog. OnTimeSetListener() {

publicvoid onTimeSet(TimePicker view, int hourOfDay,

int minute) {

dateAndTime. set(Calendar.HOUR_OF_DAY, hourOfDay);

dateAndTime. set(Calendar.MINUTE, minute);

updateLabel();

}

};

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

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

btn. setOnClickListener( newView. OnClickListener() {

publicvoid onClick(View v) {

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

Интервал:

Закладка:

Сделать

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

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


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

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

x