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();
    }

}


}

我正在切换我的 imageview 可见性。你必须改变那些地方的drawable。

于 2013-09-23T08:01:28.927 回答