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

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

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

18,319 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,428 views

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

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

6,400 views

GoogleMapを表示する

GoogleMapを表示する方法を簡単に。
機能はほとんどなく、ズームコントローラーのみ付けています。

Google API + Android 2.2以降 続きを読む…»

2,307 views

画面下にテキストを表示する [Toast]

import android.widget.Toast;
Toast myToast = Toast.makeText(this,
"テキスト",
Toast.LENGTH_LONG);
myToast.show();

//1行で実行

Toast.makeText(this, "テキスト", Toast.LENGTH_LONG).show();

続きを読む…»

2,075 views