Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有设置默认选中数据,默认选中一条或者多条 #9

Open
haoyuexiyu opened this issue Sep 18, 2017 · 5 comments
Open

Comments

@haoyuexiyu
Copy link

haoyuexiyu commented Sep 18, 2017

还有,单选后再次点击怎么还可以取消所选中的那一项

@allwith
Copy link

allwith commented Oct 12, 2017

修改setAdapter方法, addView(view);之前调用view.setSelected(true);就可以

@Nextweekends
Copy link

设置setselected不行啊

@Nextweekends
Copy link

private void initAutoFlowlayout(ArrayList mData, List skillModels) {
cvb.autoChooseSkill.setAdapter(new FlowAdapter(mData) {
@OverRide
public View getView(int position) {
View item = mLayoutInflater.inflate(R.layout.item_skill_text, null);
TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag);
tvAttrTag.setText(mData.get(position));
/ if(position == 0){
tvAttrTag.setSelected(true);
}
return item;
}
});

无法实现,选中之后 选其他会多选,点击默认的会 不选中

@kedongjun
Copy link

第一步,加多一个字段isSelcect控制是否选中,如:

@kedongjun
Copy link

第一步,adapter的实体类加多一个字段isSelcect控制是否选中,如:
Screening screening = list.get(i);
@SuppressLint("InflateParams")
View item = LayoutInflater.from(getContext()).inflate(R.layout.grade_flow_item, null);
TextView textView = item.findViewById(R.id.textView);
textView.setText(screening.name);
textView.setSelected(screening.isSelect);
return item;
第二步,重新setOnItemClickListener:
Screening screening = list.get(i);
if (screening.isSelect){
return;
}

        for (int j = 0; j < list.size(); j++) {
            Screening s = list.get(j);
            s.isSelect = false;
            adapter.getView(j).findViewById(R.id.textView).setSelected(s.isSelect);
        }

        //

        screening.isSelect = true;
        adapter.getView(i).findViewById(R.id.textView).setSelected(screening.isSelect);

可以实现默认选中。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants