To clear the strikethrough of deprecated method in Eclipse


Android is upgraded frequently. Therefore, it is often the case that the old API methods is deprecated and a new method is recommended. Now, it is likely that API methods which have been adopted since 3.x (Honeycomb) is recommended and methods which can be used even less than 2.x are deprecated.

I think that if you can accommodate the situation by Support Library, it is the best to use new API. However, if the method is not supported by the library, you are not forced to use the old API. (At least, Gingerbread has a market share close to 50% yet. For more information, please refer to Dashboards.)

If you use the old methods deprecated in Eclipse, code becomes difficult to read because the “strikethrough” is marked with in the default setting. Then this does not disappear even with the @SuppressWarnings(“deprecation”).

I do not think that even without “strikethrough” you are troubled, because the lint will mark the following warning.
deprecated_method

So I tried to check the settings to turn off the “strikethrough”.

At development of Java (Including Android), to turn off the “strikethrough” for the deprecated method is as easy as following.

  1. Open the menu Window > Preferences > Java > Editor > Syntax Colorling
  2. In Element, select “Deprecated members
  3. Remove the check mark of Enable
  4. Click Apply

syntax_coloring-en
Alternatively, It is a good idea that leaving “Enable”, change the Color or change “Strikethrough” to “Underline”. Of course, if the recommended alternative method is available you should take advantage of that.


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.

custom_dialog

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


Using the Android Support Library


Previously, in the article Android Support Library, I wrote about how to set “Support Library”.

With the “Support Library”, you will be able to create an application using the new API even on older platforms. However, when you use the code for the Fragment which is covered in Google Developers site, etc., as it is, you may result in errors.

Here, I list notes simply. (For more information, please refer to Using the v4 Library APIs.)

  1. If you use a class of the “Support Library”, import the package defined in “android.support”, instead of the native ones. (When you view the candidates of “import” package in Eclipse, two candidate should be displayed.)
  2. When you need to declare an Activity to use Fragment, you should declare the class derived from “FragmentActivity” instead of “Activity”.
  3. Instead of the method getFragmentManager() , use the method FragmentActivity.getSupportFragmentManager().
  4. Instead of the method getLoaderManager() , use the method FragmentActivity.getSupportLoaderManager().

Because there is no direct relationship between the fact “2” and to use Fragment,
you tend to overlook the fact. So you should pay special attention.

[Related article]
Android Support Library