ANDROID関連メモ書き

■DB関連


テーブルの型
TEXT -------- 正数や浮動小数点を文字列に変換
NUMERIC ---- テキストを整数か浮動小数点に変換。変換できない場合は文字列
INTEGER ---- 整数に変換
REAL ------- 浮動小数点に変換
NONE ------- 変換を行わない


カラムの制約
PRIMARY KEY
NOT NULL
DEFALT
UNIQUE
AUTOINCREMENT





PrimaryKeyの指定

項目に指定
 create table test(id integer primary key, name text);

後から指定(複数項目にKEY設定時はこれで)
 create table test(id integer, name text, primary key(id, name));


INTEGER の項目をPrimaryKeyにすると、オートインクリメント発動
対象の項目にNULLを設定すると、勝手に採番されている



●データ追加方法

・SQL文をそのまま実行する方法
SQLiteDatabase.execSQL(SQL文字列);
SELECT以外はこれでOK(CREATEとかも)

・insertメソッドを使用する方法
メソッド:public long insert (String table, String nullColumnHack, ContentValues values)

// ContentValuesに1項目ずつセットする
ContentValues values = nuw ContentValues();
values.put("項目1","項目1に対応する値");
values.put("項目2","項目2に対応する値");
...

// セットしたら☟
SQLiteDataBases.insert("テーブル名", null, values);




●DB接続方法(デバック時)

SKD内の 『platform-tools』 のadb を使用

エミュが起動しているのを確認する
>adb devices

telnet?接続
>adb -e shell

注) # ⇒LINUXコマンド

ディレクトリ移動して、データベースファイルを確認
#cd /data/data/パッケージ名/databases
#ls -l

SQLite接続
#sqlite3 データベースファイル

あとは、SQLコマンド
http://rktsqlite.sourceforge.jp/sqlite/command.html




■レイアウト関連
--- LinearLayout ------ 単純に縦か横に並べるだけの場合

android:baselineAligned ベースラインに合わせて配置するかどうかを指定します。
true:真ん中あわせ?
false:上?

android:baselineAlignedChildIndex ベースラインとなる属性を持ったWidgetのインデックスを指定します。
縦横混合の場合に、内側のレイアウトの基準指定?0から


android:gravity オブジェクトの配置方法を指定します。
配置位置の設定。複数指定の意味はよくわからん

android:orientation 配置する向きを指定します。
縦:vertical
横:horizontal

http://wikiwiki.jp/android/?UI%A5%B3%A5%F3%A5%DD%A1%BC%A5%CD%A5%F3%A5%C8%2FLinearLayout



--- RelativeLayout------ 、他のビューとの位置関係を指定することで表示される位置を決定するレイアウト


サンプル
ImageViewを基準のビューとして、TextViewを2つ配置する



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 <!-- 基準の指定 左 -->
android:layout_alignParentLeft="true"
 <!-- 基準の指定 中央(左右は左に指定したので、縦が中央) -->
android:layout_centerInParent="true"
android:src="@drawable/icon"
/>
   
<TextView  
android:id="@+id/textview1"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
 <!-- imageviewの右に配置 -->
android:layout_toRightOf="@id/imageview"
 <!-- 基準のビューがない縦方向の指定 -->
android:layout_alignParentTop="true"
android:layout_marginLeft="20dip"
android:text="TextView1"
/>
<TextView  
android:id="@+id/textview2"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
 <!-- imageviewの右に配置 -->
android:layout_toRightOf="@id/imageview"
 <!-- textview1の下に配置 -->
android:layout_below="@id/textview1"
android:layout_marginLeft="20dip"
android:text="TextView2"
/>
</RelativeLayout>










--- TableLayout ------ 表形式の場合。業務系はこれがメインな予感

android:collapseColumns 折り畳む列を指定します。
android:shrinkColumns 縮小する列を指定します。
android:stretchColumns 幅を拡張できる列を指定します。
※複数指定はカンマ区切りで。0から





--- TableRow.LayoutParams ------

android:layout_column - Viewのカラムを指定
android:layout_span - Viewの使用する範囲を指定

http://wikiwiki.jp/android/?UI%A5%B3%A5%F3%A5%DD%A1%BC%A5%CD%A5%F3%A5%C8%2FTableRow.LayoutParams





---


android:layout_gravity=""  入力枠の位置指定
android:gravity=""  入力内容の位置指定

center
right
left




android:layout_weight="1"
画面の残りを使いたい場合に指定
中間のウィジットに設定すれば、その下のウィジットは一番下まで下がる

なんか曲者のリストちゃん
simple_list_item_1 を使う簡単なやつはすぐ出来るけど、
複数項目対応リストにすると、訳わかんない感じになる。
サンプル持ってきても動かないし、、、

やっとSimpleAdapter使うパターンでとりあえず、表示出来た







Eclipse上で画面作成中にGraphicalLayoutタブを開くと、
日本語が表示されたり、されなかったりする問題

エミュ上では、表示されるので、画面作成ツールの問題っぽい
解決策はまだわからない


■その他

●画面遷移時
忘れがちなのでメモ

//次の画面に遷移させる
Intent intent = new Intent();
intent.setClassName("パッケージ名", "クラス名(パッケージ名から)");
startActivity(intent);

AndroidManifest.xml にActivity追加する

値の受け渡し

●トースト表示

// トースト表示
Toast.makeText(this, ”表示文字列”, Toast.LENGTH_LONG).show();




・MAP関連


Maps API Keyの取得
http://wikiwiki.jp/android/?Maps%20API%20Key%A4%CE%BC%E8%C6%C0
debug.keystore のありか:Win7の場合、Docment and Settings ⇒ Users


地図/位置情報/GPSを使うAndroidアプリを作るには
http://www.atmarkit.co.jp/fsmart/articles/android16/android16_1.html


ADT Pluginのインストール
http://www.javadrive.jp/android/adt/index1.html


新規プロジェクトを作成する際、ビルド・ターゲットに“Google APIs”がない場合には
http://tk-factory.net/wordpress/?p=2070