3

私のアプリケーションでは、いくつかのテキストビューと画像を含むカスタムリストビューがあります.デフォルトの画像ビューには灰色の矢印マーク画像が含まれています.私はここまで来ました.私の問題は、ユーザーがリスト内の項目をクリックすると矢印マークが変わることです.青色の矢印マークの画像に、残りはすべて灰色のみです。選択したリスト項目の画像は青色になります。どうすればいいですか。誰か助けてください。

事前に感謝します。

4

2 に答える 2

2

この機能は、tag作成時にリスト項目に整数を設定することで実現できます。そして、選択を行うときに、条件が満たされている場合はそれを取得tagしてアイテムと比較し、要件に応じてそれを変更し、他のすべてを逆のアイテムに変更しますindexindex

于 2013-09-23T07:52:46.583 に答える
1

アダプタの getView() メソッドで View.onclickLister を実装し、特定のアイテムの onclick でその矢印のドローアブルを青に変更します。

    private int resource;
private Context mContext;
public int mPosition;
public static int curSelected = -1;
static String time ;


public CustomDateRowAdapter(Context context, int _resource,
        List<DayPickerTo> objects,) {
    super(context, _resource, objects);
    allItems = objects;
    resource = _resource;
    mContext = context;


}

@Override
public View getView(final int position, View convertView,
        final ViewGroup parent) {

    RelativeLayout rel = null;
    if (null == convertView) {

        String inflater = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater vi;
        vi = (LayoutInflater) getContext().getSystemService(inflater);
        rel = (RelativeLayout) vi.inflate(resource, rel, true);

    } else {
        rel = (RelativeLayout) convertView;

    }

    rel.setTag("Txt:" + position);
    final ImageView checkBox = (ImageView) rel
            .findViewById(R.id.checkedIcon);
    if (position == curSelected) {
        checkBox.setVisibility(View.VISIBLE);
        mPosition = curSelected;
    } else {
        checkBox.setVisibility(View.INVISIBLE);

    }

    checkBox.setTag(position);
    dateText.setTag("text:" + position);

    final RelativeLayout rel1 = rel;

    // click Listener of day list
    rel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            int checkslot=0;
            String seletedPosition = (String) v.getTag();
            String[] splitted = seletedPosition.split(":");
            int tag = Integer.parseInt(splitted[1]);
            mPosition = tag;


            clearChecked(v, parent);

            ImageView checked = (ImageView) rel1.findViewWithTag(tag);

            if (null != checked) {
                checked.setVisibility(ImageView.VISIBLE);
                checked.setTag("Checked");
                notifyDataSetChanged();
            }


        }
    });

    return rel;
}



void clearChecked(View view, View parent) {
    // clearing current selecting
    ImageView checkedBox = (ImageView) parent.findViewWithTag(curSelected);
    if (checkedBox != null) {
        checkedBox.setVisibility(View.INVISIBLE);
        checkedBox.invalidate();
    }
    // getting new current selection
    String tag = view.getTag().toString();
    String[] splittedTag = tag.split(":");
    Logging.i(TAG, "[clearChecked]", "Selected: " + tag);
    curSelected = Integer.parseInt(splittedTag[1]);
    // setting new current selection
    ImageView newChecked = (ImageView) parent.findViewWithTag(curSelected);
    if (newChecked != null) {
        newChecked.setVisibility(View.VISIBLE);
        newChecked.invalidate();
    }

}


}

イメージビューの可視性を切り替えています。それらの場所でドローアブルを変更する必要があります。

于 2013-09-23T08:01:28.927 に答える