2013年3月14日木曜日

TextViewに表示させようとして落ちる

すごく単純なところなのに詰まったのでメモ。
TextViewに表示させようとして、以下のエラーで落ちた。

android.content.res.Resources$NotFoundException: String resource ID #0x5dc

TextViewに設定しているidの名前も間違ってないし、クリーンもしたし、
eclipseの再起動もしたしなんで???と思っていたら、

原因は「int型をセットしていた」ことだった。


ちょっと疑問には思ったけど、コンパイルエラーにならないからいいやと思っていたらダメだった。

かなり残念すぎるバグ・・・。

2013年3月12日火曜日

ListViewの中にImageButtonを使うとonItemClickが呼ばれなくなる?

ListViewをカスタマイズして実装しているときに、
リスト1つ1つの中にImageButtonがあると、
リスト全体のクリックイベントも、ImageButtonのクリックイベントも拾ってくれないらしい。

解決策としては、
1. xmlのImageButtonに
android:focusableInTouchMode="false"
android:focusable="false"
を追加する

または

javaで以下を設定する

((ImageButton)v.findViewById(R.id.recommend_checkin)).setFocusableInTouchMode(false);
((ImageButton)v.findViewById(R.id.recommend_checkin)).setFocusable(false);

2. ***_item.xml(リストの中身のレイアウト)の一番外に
android:descendantFocusability="blocksDescendants"
を追加する

例)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:gravity="center" >

<ImageView
        android:id="@+id/recommend_product_image"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="#e5fff7"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:gravity="left|center_vertical"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/recommend_product_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/recommend_pickup_comment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>


これで、全体のクリックイベントを拾ってくれるようになる。


さらに、ImageButtonのクリックイベントを拾うためには、
adapterの中でonClickイベントを拾ってやればいいらしい。

参考URL
http://tomstay.hatenablog.jp/entry/20110421/1303391426
http://blog.babukuma.com/2010/01/android-listviewbutton.html

2013年3月8日金曜日

mysqlで、任意の順番で取得したい場合


ex.)
type が1, 5, 4, 2, 3の順番で取得する場合

ORDER BY FIELD(type, 1,5,4,2,3)