redev

technical miscellaneous memorandum

Android

Preference画面からNumberPickerダイアログを作成する

preference.xml <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="category"> <Preference android:key="key" android:title="title" /> </PreferenceCategory> </PreferenceScreen> dialog_hoge.xml

ListViewの下に何かしら設置するとき

LinearLayoutでそのまま配置するとListViewと部品が重なるが、ListViewにandroid:layout_weight="1"を指定すると重ならない。 <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </listview>

TabLayoutを使うとき

build.gradleにcompile 'com.android.support:design:23.+'と追記する必要がある。 しないとjava.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/internal/widget/TintManager; が発生した。 出典: Android Studio2.0: TabLayoutを…

TabNavigationモード

import android.app.ActionBar; import android.app.Activity; import android.app.FragmentTransaction; import android.os.Bundle; import android.view.Menu; public class MainActivity extends Activity implements ActionBar.TabListener { @Override …

ActionItemのイベント

ActionBarとインタラクション制御 - mixi-inc/AndroidTraining のActionBar課題52つのActionItemをActionBarに表示させ、片方は新しいActivityを起動、もう一方はMainActivityを終了させる。 public class MainActivity extends Activity implements ActionB…

ActionBarのAppIconNavigationで「戻る」操作

AppIconに「 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); : getActionBar().setDisplayHomeAsUpEnabled(true); } タップイベントを取得 @Override public boolean onOptionsItemSelected(MenuItem item) { s…

ボタンのクリックイベントでブラウザを立ち上げる

Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("http://www.yahoo.co.jp"); intent.setData(uri); startActivity(intent); 最初、なぜか4行目をsendBroadcast(intent)にしていて起動しなかった。

Intent.FLAG_ACTIVITY_NO_HISTORY

を指定すると履歴にスタックされない。 Intent intent = new Intent(IntentActivity1.this, NewActivity3.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); 具体的には、↑のNewActivity3に移った後に「戻る」ボタンなどで…

AaptException: Failed to crunch file

メッセージングと通知 - mixi-inc/AndroidTraining の実習1で表題のエラーが出てサンプルが起動しない。 ので、調べたら同様の事例があった。 ↓ Error: com.android.builder.internal.aapt.AaptException: Failed to crunch file | ファイルパスの上限に引っ…

Yahoo気象情報APIでJSONデータを取得する

ネットワーク通信 - mixi-inc/AndroidTraining の実習と課題3でYoutubeのAPIが使えないので他のAPIを使用することにした。APIはこちら 気象情報API - Yahoo!デベロッパーネットワーク 取得したJSONデータ { "ResultInfo":{ "Count":1, "Total":1, "Start":1,…

IntentServiceを用いた非同期処理の落とし穴

非同期処理 - mixi-inc/AndroidTraining の実習・課題で saveボタンでIntentServiceを呼び出し、SharedPreferenceにデータを書き込む loadボタンでAsyncTaskLoaderからSharedPreferenceのデータを読み込む という処理を作成したが、データが取れない(ロード…

SharedPreferencesとInternal Storage

保存・読み込みが出来るのは分かったが、データの実体がどこにあるのか分からない…。 ファイラーで見ようにも、MODE_PRIVATE にしているから見えないのか? --- 追記(17/01/17) SharedPreferenceの内容の確認 sdk/toolsとsdk/platform-toolsにパスを通し、コ…

Intentで独自クラスを渡す

直列化とコレクション、永続化 - mixi-inc/AndroidTraining の「コレクション・直列化」の課題2で、以下のフィールドを持つ User クラスを作成した。 public class User { private int id; private String name; private int age; private String keyword; p…

layout_marginLeftが悪さをする?→(解決)

直列化とコレクション、永続化 - mixi-inc/AndroidTraining の「コレクション・直列化」の課題2activity_main.xmlの中で <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </linearlayout>

notifyDataSetChanged()でListViewを更新する

出典: notifyDataSetChanged()でListViewが更新されない - Life is Really Short, Have Your Life!!↓ここ ListViewとViewPager - mixi-inc/AndroidTraining の課題5でデータの更新処理を行うが、この際にadapter.notifyDataSetChanged()を使用する。 この課…

ListViewへのイベント付与→アラート表示

出典:Androidのお勉強 第二回 ListViewと独自Adapterについて - Qiita の練習問題1 ListSampleActivityに見よう見まねで以下を記述してアラートが表示されたが、 ---引用ここから--- listView.setOnItemClickListener(new AdapterView.OnItemClickListener(…

【保留事項】バックキーでのアプリ終了

出典:Androidのお勉強 第一回 環境構築と画面遷移 - Qiita の問題2 MainActivityに public void finish() や public void finishAndRemoveTask() をただオーバーライドするだけだとタスク一覧に残るし、□ボタン押下後の一覧にも表示される。つまり、これら…

AndroidManifest.xml の <category android:name="android.intent.category.LAUNCHER">

出典:Androidのお勉強 第一回 環境構築と画面遷移 - Qiita ---引用ここから--- <category android:name="android.intent.category.LAUNCHER" /> この指定は、このAcitivityが呼ばれた際に、デバイスのホーム画面にランチャーアイコンを作成するという挙動をとります。この指定を今後追加するActivityにバカみたいに何も考</category>…

幅を決めるタグ wrap_content / match_parent / fill_parent の違い

出典:http://www.agyou.com/technical/422.html Android初期の頃には fill_parent しかなかったが、 Android2.2 (API 8)以降から match_parent に名称が変更された。 fill_parentは残され続けている。即ち名残。