Android error this package depends on Missing SDK Platform Android API 17

Android

Android error this package depends on Missing SDK Platform Android API 17

Android SDK Managerから、Android4.2 API17をダウンロードしようとしても、MIPSとかARMだけが表示されていて、SDK Platformが表示されません。
MIPSとかARMをダウンロードしようとしても、上記のようなそもそもSDKが入っていないので、MIPSとかARMはインストールできないよ、という警告が。

これ、次のように解決しました。

  1. Android SDK Managerの上部のメニュー Tools→Optionをクリック
  2. Force https://… とあるところにチェック
  3. Clear Cacheのボタンを押して、キャッシュをクリア
  4. すると、Android SDK Managerのリストに、Android4.2 API17が表示され、無事ダウンロードできました。

Android dipとdpの違い

Android

Android dipとdpの違い

Androidの画面を開発する時に利用するdipとdpという単位ですが、同じ意味です。

古い本だとdipってなってることが多いですよね。

Android This text field does not specify an inputType or a hint

Android

Android This text field does not specify an inputType or a hint

Androidのレイアウトファイルで、入力フォームを表示する部分で、黄色のエラーで上記のようなエラーが表示されることがあります。

 <EditText
   android:id="@+id/nick_name"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   >

android:inputTypeという、パラメーターが足りないということのようです。

 <EditText
   android:id="@+id/nick_name"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   android:inputType="text" >

一番最後にinputTypeを付与してなおりました!

ちなみに、

 <EditText
   android:id="@+id/email"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   android:inputType="text" >

とか書くと、これも下記のエラーが表示されます。

The view name (@+id/email) suggests this is an e-mail address, but it does not include ‘textEmail’ in the inputType

どうやらこれはEmailを入力するフォームのようだけど、テキストタイプがEmailになっていないよ、ということのようです。

 <EditText
    android:id="@+id/email"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="textEmailAddoress" >

ちなみに、上記はtextEmailだとエラーになります。textEmailAddoressが正解です。

他にも、下記で

 <EditText
    android:id="@+id/phone_number"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="text" >

The view name (@+id/phone_number) suggests this is a phone number, but it does not include ‘phone’ in the inputType

と出ます。正しくは、下記ですね。

 <EditText
    android:id="@+id/phone_number"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="phone" >

どうですか?
Androidの開発環境さん、優しくないですか?!
ぁたし なぃちゃったよ…w

idに適当な文字を割り振るのではなくて、ちゃんとテキストフォームの属性を指定する名前をつけるべし、です。

Android TextViewにリンクを張る

Android

Android TextViewにリンクを張る

ボタンとか作らずに、簡単にURLにリンクを張りたい時ありますよね。
レイアウトファイルのTextViewを利用するだけで、URLへのリンクが簡単に作れます。

 //例 main.xml内
 <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:autoLink="web"
       android:text="@string/register_url" 
       android:textSize="16dp">
 </TextView>
 //例 strings.xml内
 <string name="register_url">http://onlineconsultant.jp</string>

http://onlineconsultant.jpへのリンクが作られます。
HTMLのように、日本語などにリンクを張るのは、この方法ではできないのが残念です。

Android TableLayoutに線を引く

Android

Android TableLayoutに線を引く

TableLayoutはレイアウトのxmlファイルの中で、テーブルを作れるタグです。
HTMLみたいに、border:1pxとかやって線を引けそうですが、できません。
仕方ないので、テーブルの背景に線の色を指定し、行であるTableRowの背景に城を設定し、marginを設定して隙間を空けることで、表に線をつけたように見せる方法を取ります。

以下、サンプルです。

 <!--menu.xml -->
 <TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_margin="5dip"
    android:orientation="vertical"
    android:background="@color/grey05"
    android:padding="1dp"
  >
 
    <TableRow
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:gravity="center_vertical"
       android:background="@color/white"
       android:padding="5dp"
       android:layout_marginBottom="1dp"
       >
 
      <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/indispensable"
         android:textColor="@color/red_text" >
      </TextView>
      <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/company_group_id"
         android:textColor="@color/black_text" >
         </TextView>
            
    </TableRow>
 </TableLayout>
 <!--colors.xml-->
   <color name="grey05">#cccccc</color>
   <color name="white">#FFFFFF</color>