Android Dialog(2) -Custom Dialog-

In the previous article, I have taken up an example of displaying a ready-made dialog, AlertDialog. This time, I will take up creating and displaying a custom dialog.

For time setting, there are ready-made dialog, TimePickerDialog. As a simple example, we try to make a custom dialog that has a TimePicker widget and CheckBox to allow you to check it.

First, I define the layout of the dialog and save it as xml file in res/layout. Here, it is defined as follows res/layout/test_dialog.xml.

Next, in onCreateDialog method, I apply the layout to my dialog. Since this example is a custom dialog, I directly generate an instance of Dialog without using the Builder.

1.Case without DialogFragment

2.Case with DialogFragment

When you display the above dialog, you can see the following screen.


For information on how to display the dialog that you define, please refer to the article Android Dialog(1)

[Related articles]
Android Dialog(1)
Android Dialog(1) – 2 Supplement

Pitfalls of how to remove the file from Git management

If you want to remove file “a” from currently Git management, you will do as follows.

And you may want to define “.gitignore”. This approach has been introduced in many places.

But in this case, when you checkout the past commit, you will see that the file “a” was overwritten by the previous contents. The file was supposed to be outside the control of Git.

You can reproduce the fact as follows.

By the last checkout, the contents of “a” will be rewritten to “initial”. In other words, even if “unmanaged” the file, the contents of the current file will be lost to be “managed” and go back to the past.

In this case, it is fatal in that because there is no history of changes of management outside, you can not retrieve the current file “a”.

I’ve also studied to try if you do not create “.gitignore”.

At the time you are trying to rewrite “a” with the last checkout, you will fail with an error. I think this is a desirable result. Git should remind you here, that unmanaged file “a” were managed at the past. If you moved file “a” somewhere once, you can checkout to get back “a” in the past.

Why the difference between the two situations happen this?

If there is “.gitignore”, the current file “a” has no interest to Git. Therefore Git would also be carried out without having to worry about checkingout to overwrite.
On the other hand, if there is no “.gitignre”, because “a” is “Untracked” file, Git does not checkout to overwrite it on its own.

Is this correct?

However, if there is no “.gitignore”, you are inconvenient to be displayed every time “Untracked”. Is not the only way to rm all “a” back in the past using rebase -i?
I am investigating whether there is any good way.


In Android programming, to know the status of the battery, write the code as shown below.

According to the reference, the values of the status are five of the following.


To determine whether during charging, we describe below.

We can understand that “battery is charging” or “battery is full, so can not be charged any more”.

Then, when we determine whether during discharging, what’s the difference of the following two ?


I investigated the value of “status” when external power is not connected (= discharging) to my terminals.

SO-02C (Xperia acro/Android2.3): BATTERY_STATUS_DISCHARGING
SO-03C (Xperia ray/Android2.3): BATTERY_STATUS_DISCHARGING
FAR70A (Fujitu Arrows/Android4.0): BATTERY_STATUS_NOT_CHARGING
TF-201 (Asus Eee Pad/Android4.1): BATTERY_STATUS_NOT_CHARGING

I guess that the smartphones will return BATTERY_STATUS_DISCHARGING and the tablets (of 10inches) will return BATTERY_STATUS_NOT_CHARGING. (I want to know which values the tables of 7inches or Android3.2 will return. But I’m not in possession of them.)

Therefore, when examining whether the terminal is discharging, we write as follows.

* I was exposed to here the code to check the staus of the terminal.