カテゴリー
SugiBlog Webデザイナー・プログラマーのためのお役立ちTips

自動終了してくれる非同期サービス

時間のかかる処理を非同期で実行するためのクラスIntentServiceを利用します。
メインスレッドとは別のプロセスで処理が実行されます。
これはメインのActivityに依存せず処理をするので、Activityが終了しても処理が
終了するまで続きます。 続きを読む…»

3,847 views

ファイル入出力 [Android]

Androidでは、アプリケーション毎に専用のディレクトリが設けられています。
アプリケーション毎に「/data/data/パッケージ名」となっていて、
更にそれ以下に以下のように領域が分かれています。

databases データベースの保存
shared_prefs 設定ファイルの保存
files ファイルの保存

今回はファイルの入出力なので、「files」ディレクトリを利用します。
アクセスする際はファイルまでのパスは不要です。

続きを読む…»

3,746 views

データベースの内容をListViewに表示 [Android]

ListAdpterを使って、データベースの内容を一括で簡単にリスト表示
CursorとListAdpterを組み合わせて使うときは、Cursorオブジェクトに「_id」列を含んでいないといけません。
続きを読む…»

18,330 views

Androidでデータベースを利用する【SQLite】

データベースが簡単に利用できるSQLiteOpenHelperクラスを使用します。
プラットフォームは1.6で作成。

【HelloSqliteActivity.java】

package android.sample.sqlite;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;

public class HelloSqliteActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MySqlite helper = new MySqlite(this);
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor c = db.query("TABLE_NAME",
      new String[] { "number", "latitude", "longitude" },
      null, null, null, null, null);
    startManagingCursor(c); //リソースの扱いをActivityに委ねます
    boolean isEof = c.moveToFirst();
    TextView textView1 = (TextView)findViewById(R.id.textView1);
    String text="";
    while (isEof) {
      text += String.format("物件番号 : %s\r\n緯度 : %.6f\r\n経度 : %.6f\r\n\r\n",
        c.getString(0), c.getDouble(1), c.getDouble(2));
      isEof = c.moveToNext();
    }

    textView1.setText(text);
    c.close();
    db.close();
    }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }
    
}

続きを読む…»

5,434 views

GoogleMap上にGPSで取得した現在地を表示

GoogleMap上にGPSで取得した現在地を表示します。
前回からの続きなので、レイアウトとマニフェストは割愛します。 続きを読む…»

6,406 views