基本の割に初心者にとって使うのにハードルが高いview、ListView。 ネット調べると色んなパターンで書かれた例が出てくると思います。 何も知らずにAndroid 1.6とかの時代に書かれたような出どころが不明なサンプルコードをコピペしてうまくいかなくて心が折れるみたいなことを防ぐために、インターネットに出回っているサンプルコードをパターン化して列挙しました。パターン1が一番良くなくて、パターン3あるいはパターン4にするといいと思います。 インターネットで調べててAndroid 1.6とか2系の葬式UIが出てきたら、それは昔に書かれたものでそっと閉じたほうがいいです。 Adapterとは AdapterはviewとDataSourceの橋渡しをするものです。 private void setupListView(List<User> userList) { UserAdapter ad
layout_weightの留意点 layout_weightは、複数のViewを任意の大きさの割合で配置することができるコマンドであり、とても有益である。このコマンドの留意点は次のとおりである。 絶対の位置では無く、相対的な位置を設定する。このため、物理画面の大きさの違いに関係無く、全てのサイズの画面に対応できる。 横方向で使う場合:layout_widthの値を"0dp"にすること。具体的には次のように書く。android:layout_width="0dp" この値を"fill_parent"にした場合、layout_weightの数値が低いViewが大きく配置される。物好きな人はお試しください。 この値を"wrap_content"にした場合、各Viewの配置割合は不正確になる。 縦方向で使う場合には、(layout_widthを0dpにするのではなく)layout_heightの
githubで★を集めてるandroid best practiceが勉強になるなぁと感心しておりまして、 思い切って翻訳していいかどうか問い合わせてみると快諾いただけたので翻訳してみました。 (Eclipse + ADTの話もでてますがそのまま訳してます。) 原文 : https://github.com/futurice/android-best-practices (Qiitaに投稿するついでに本家のリポジトリにもプルリクしてくれって言われてるので少し待てばそちらでも見れると思います。) この場を借りて、@askaさん、添削ありがとうございましたm_ _m 大変助かりました。 Summary Gradleで推奨されるプロジェクト構成で開発しよう パスワードや注意を要するデータはgradle.propertiesに書こう 自分でHTTP Clientは作らず、VolleyやOkHttp
この投稿はAndroid Adevent Calendar 2014 の7日目の記事です。 Androidアプリがどのような構成でできているか、ご存知ですか。 基本的にはエンジニアリングが必要なのですが、UIのレイアウト部分はアルゴリズムの部分からすこし切り離されています。 そしてそのレイアウト部分はXMLという、HTMLやCSSがわかる方なら少しの学習でも扱うことができる言語で書かれています。 XMLの学習を始めた頃、デザイナー向けにXMLの基礎について書かれた資料が見つけられなくて困ったので、自分用のメモも兼ねて基本的な使い方についてまとめます。 ※デザイナー視点で書いているので、エンジニアにとっては物足りないものになっているかと思います。 Androidアプリの構造 Androidアプリはたくさんのディレクトリ(フォルダ)とファイルから構成されています。ですがデザインを編集していく場
前回はSimpleCursorAdapterを継承して新しいクラスを作ってたけど、listenerいらないならそこまでしなくても大丈夫。 main.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> list_row.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/
SimpleCursorAdapterはその名の通り、カーソルで取得した各行について「バインド元の(カラムの)値を単純にバインド先の(レイアウト要素の)値として使用する場合」には、簡単で便利な方法である。基本的には以下のような流れになる。 // カーソル取得(daoはDBへのクエリ処理を行うクラスのインスタンス。fetchAll()はそこで定義しているメソッド) Cursor c = dao.fetchAll(); // バインド元のカラムのカラム名 String[] from = {"col1","col2"}; // バインド先のレイアウト要素のリソースID int[] to = {R.id.item1, R.id.item2}; // アダプターの作成 SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layo
やり方が分からなかったのですが、Twitterで方法を教えて貰いました。 やりたい事のイメージ ActivityがRunning状態で。左画像レイアウト状態のとき、動的に右画像レイアウト状態にする。 やりかた XML定義 TextViewとButtonを定義します。ここは普通。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/txt" android:text
ListView は Graphical Layout で作ったまま使ってはいけない ListView の表示時に無駄が多すぎなのではないか? というエントリを書いたところ、いならさんという方からコメントをいただきました。 【Androidアプリ】AdapterのgetView()が必要以上に呼ばれる件|べっ、別にWeb言語のことなんか好きじゃないんだからねっ!!/// という記事によると、layout_width と layout_height が両方共 fill_parent じゃないと、この現象が起こるとのこと。 まさに、ご指摘の通り! ListView の height が以下のように wrap_content になっていました。 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=
リストビューの一番下の項目にボタンを追加する。 そのボタンを押すとリストビューの項目が追加されていくような作りにする。 実際には項目を追加するわけではなく、リストビューのフッターとかヘッダーに別のレイアウトを登録する。 それが押された時とかに何か処理をするようにする。 addFotterViewはsetAdapter()の前に呼ばないといけない addHeaderViewもあるよ 検索した事 android ListView 一部 別の項目 android ListView ボタン addFotterView android ListView LastItem android ListView 一番下の項目 開発環境 Eclipse IDE バージョン: 4.2.1 package com.example.trylistview04; import android.os.Bundle; i
記事の詳細画面を作ります。 今回は1Activity で一覧と詳細の2画面作ります。 それぞれのレイアウトをインスタンスにしてとっておき、setContentView() で画面遷移させます。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" and
ListView SimpleAdapter listViewはadapterを用いてデータをセットする。まず、SimpleAdapterを用いる。SimpleAdapterのコンストラクタの定義は以下。 SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) コンストラクタの引数は以下。 引数 説明 context 表示するView。今回はthis。 data ListViewに表示するデータで、MapのListでデータを保持する。 resources ListViewに表示するウィジェットの定義されているresourceのid。 from ListViewに表示するdataのMapのキー項目。 to ListViewに表示するウィ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く