1

私はアンドロイドのビューバインダーに少しこだわっています

ここに私のコードがあります:

    public void displayAllAlerts() {
    Cursor mCursor = mDbAdapter.fetchAllAlerts();


    //Bind Columns
    String[] columns = new String[] {
        DbAdapter.KEY_ID,
        DbAdapter.KEY_PLACE,
        DbAdapter.KEY_LONG,
        DbAdapter.KEY_LAT,
        DbAdapter.KEY_STATUS
    };

    int[] to = new int[] {
            R.id.txtId,
            R.id.txtPlace,
            R.id.txtLong,
            R.id.txtLat,
            R.id.tglBtnAlert
    };

    mSimpleCursorAdapter = new SimpleCursorAdapter(
            this,
            R.layout.layout_lvrow,
            mCursor,
            columns,
            to,
            0);



    ListView lvAlerts = (ListView) findViewById(R.id.lvAlerts);
    lvAlerts.setAdapter(mSimpleCursorAdapter);


}

問題は、「DbAdapter.key_status」がデータベースで int としてフォーマットされていることですが、トグルボタンのステータスであるため、何らかの方法でブール値に変更する必要があります。

.setViewBinder を使用する必要があることはわかっていますが、開始する方法がわかりません。

いくつかのチュートリアルから次のことを試しましたが、うまくいきません:

    mSimplecursorAdapter.setViewBinder(new ViewBinder() {

       public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {

            if (aColumnIndex == 5) {
                String strBool = aCursor.getString(aColumnIndex);
                ToggleButton tb = (Togglebutton) aView;
                if (strBool=="0") {
                    tb.setChecked = false;
                }else{
                    tb.setChecked = true;
                }
            return true;
     }

     return false;
}

前もって感謝します

(Androidの開発者サイトも使用しようとしましたが、本当に頭痛の種です)

4

1 に答える 1