3

私はこの質問が以前に尋ねられたことを知っていますが、エレガントな解決策を見つけることができないようです。

ユーザーがクリックしたものに応じてサイズを変更できるカスタムカーソルアダプターに支えられたカスタムチェック可能な相対レイアウト(チェックボックスと他のテキストビューを含む)を使用するリストビューで選択されたチェックボックスを追跡するにはどうすればよいですか(ユーザーをフィルタリングします)選択)。

カスタムカーソルアダプターを使用するリストビューアクティビティがあります(ビューのリサイクルを利用するためのviewHolderクラスとともに、bindviewおよびnewview関数の適切なオーバーライドがあります)。

ユーザーが行項目をクリックすると、リストがフィルタリングされ、loadmanager が再起動されて、フィルタリングされた新しいリストが表示されます。これは、リストビューのサイズが常に変化していることを意味します。さらに、タグの設定と取得とともにチェックボックス onclicklistener オーバーライド全体を実装しようとしましたが、 bindview() メソッドで何をしても、チェックボックスはチェックされません (チェック可能な行内にあるためである可能性があります)。 . また、getview(または私の場合はbindviewメソッド)のチェックボックスonclicklistenerオーバーライド全体と、私が見た多くのソリューションには常にサイズが変化するリストビューがないという事実に本当に混乱しています。

どんな助けでも大歓迎です。

これが私のカスタム カーソル アダプター クラスです。

    public class TaskListViewAdapter extends CursorAdapter {

    private LayoutInflater mLayoutInflater;

    public TaskListViewAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);

        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        ViewHolder holder = (ViewHolder) view.getTag();
        int nTaskStatus;
        int nTaskType;
        int nSuite;
        String nTaskServiceTextColor;
        String nTaskServiceBackgroundColor;
        String nSuiteValue;

        if (holder == null)
        {
            // Creates a ViewHolder and store references to the children views we want to bind data to.
            holder = new ViewHolder();

            holder.taskScreenCheckBox = (CheckBox) view.findViewById(R.id.taskScreenCheckBox);
            holder.taskScreenRowText11 = (TextView) view.findViewById(R.id.taskScreenRowText11);

            view.setTag(holder);
        }

        // Getting the data from the cursor and setting the row elements appropriately
        if (cursor != null) {


            holder.taskScreenRowText11.setText(cursor.getString(cursor.getColumnIndex(DatabaseAdapter.KEY_TASKS_NUMEROAPPEL)));

        }
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final View view = mLayoutInflater.inflate(R.layout.task_screen_row, parent, false);
        return view;
    }

    /**
     * 
     * 
     *         A viewholder that stores each component of the task_screen_row view.
     * 
     */
    static class ViewHolder {
        CheckBox taskScreenCheckBox;
        TextView taskScreenRowText11;

    }
}

これが私のカスタム Checkable 行レイアウトです。

    package com.courrierplus.mobi;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.RelativeLayout;

public class CheckableRelativeLayout extends RelativeLayout implements Checkable {

    private CheckBox mCheckbox;

    public CheckableRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean isChecked() {
        return mCheckbox.isChecked();
    }

    @Override
    public void setChecked(boolean isChecked) {
        mCheckbox.setChecked(isChecked);
    }

    @Override
    public void toggle() {
        mCheckbox.toggle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        final int childCount = this.getChildCount();
        for (int i = 0; i < childCount; ++i) {

            View v = getChildAt(i);
            if (v instanceof CheckBox) {
                mCheckbox = (CheckBox) v;
            }
        }
    }
}

私の ListViewActivity では、ユーザーが行をクリックすると、onListItemClick 関数が呼び出され、カスタムアダプターで newView コードが呼び出され、カスタムのチェック可能な行が膨らみ、その中のチェックボックスがチェックされます。

私の問題は、カスタム アダプターの bindView 内でチェックボックスを取得し、手動でチェックボックスをオンに設定しようとすると機能しないことです。また、チェックされたものとチェックされていないものを追跡する方法がわかりません。

4

1 に答える 1