0

補助的な問題

こんにちは、誰かが私がの行動を理解するのを手伝ってくれませんSimpleCursorAdapter.ViewBinder.setViewValueか?

の行ごとに複数回呼び出されているようですListView。呼び出しの数は、ListViewの行数に依存しますか?SimpleCursorAdapterまたは?のカーソル内のアイテムの数 また、関数に渡されるパラメーターの重要性は何ですか?

主な問題

ListViewの単純なを作成しようとしているときに、この奇妙な問題が発生していますCheckedTextViews。チェックされる行の不透明度を下げたかったのです。私が書いたコードは、余分な1行の不透明度を常に減らすことを除いて、機能しました。

のlayout_heightListViewをmatch_parentにすると、問題が解決する場合がありました。しかし、編集のためにキーボードを開いても問題は解決せず、どういうわけかListViewが必要になります。


ここでコードを見つけてください

項目を入力するコードListActivity

private void fillDataToList() {
    Cursor all_taskCursorCursor = mDbHelper.fetchAllTask();
    startManagingCursor(all_taskCursorCursor);

    String[] from = new String[]{TaskDbAdapter.KEY_TITLE};
    int[] to = new int[]{R.id.task_title};

    SimpleCursorAdapter tasks = new SimpleCursorAdapter(this, R.layout.task_row, all_taskCursorCursor, from, to);

    tasks.setViewBinder(new ViewBinder() {

        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if(columnIndex == 1) {
                CheckedTextView ctv = (CheckedTextView) view;

                String text = cursor.getString(cursor.getColumnIndexOrThrow(TaskDbAdapter.KEY_TITLE));
                boolean checked = cursor.getInt(cursor.getColumnIndexOrThrow(TaskDbAdapter.KEY_COMPLETED)) == 1 ? true : false; 

                ctv.setText(text);
                ctv.setChecked(checked); 

                if (checked == true) {
                    AlphaAnimation animation = new AlphaAnimation(1, 0.25f);
                    animation.setFillAfter(true);
                    ctv.setAnimation(animation); 

                    ctv.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                }

                return true;
            }

            return false;
        }
    });

    setListAdapter(tasks);
}

ListViewのレイアウト-

<?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="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</ListView>

<TextView
    android:id="@android:id/empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/no_task"
    android:padding="10dp"
    android:gravity="center_vertical|center_horizontal"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

各行のレイアウト-

<?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="fill_parent" >

<CheckedTextView
    android:id="@+id/task_title"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:padding="10dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" />

</LinearLayout>
4

1 に答える 1

0

この問題は、if (checked == true) の部分に else 条件を 1 つ追加することで解決しました。

最終的なコードは次のようになります -

if (checked == true) {
    AlphaAnimation animation = new AlphaAnimation(1, 0.25f);
    animation.setFillAfter(true);
    ctv.setAnimation(animation); 

    ctv.setPaintFlags(ctv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
    ctv.setPaintFlags(ctv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}
于 2012-05-10T06:34:44.307 に答える