
ConstraintViewEventItem 클래스 - 리스트뷰를 구성
public class ConstraintViewEventItem extends ConstraintLayout implements Checkable {
boolean delchecked = false;
public ConstraintViewEventItem(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setChecked(boolean checked) {
delchecked = checked;
if(isChecked()){
this.setBackgroundColor(Color.rgb(255, 71, 26));
}
else{
this.setBackgroundColor(Color.rgb(255, 255, 255));
}
}
@Override
public boolean isChecked() {
return delchecked;
}
@Override
public void toggle() {
delchecked = !delchecked;
}
}
ActivityMain.java - toggleDelMode()
public void toggleDelMode(){
if(deletemode == true){
newBtn.setEnabled(true);
delBtn.setText("delete");
listview.clearChoices();
int count = listview.getCount();
ConstraintViewEventItem temp;
//NEED TO SET COLOR TO WHITE
listview.setChoiceMode(ListView.CHOICE_MODE_NONE);
}
else if(deletemode == false){
newBtn.setEnabled(false);
delBtn.setText("delete confirm");
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
deletemode = !deletemode;
}
이런 식으로 리스트뷰 중의 몇 아이템을 삭제할 수 있는 기능을 만들고 있는데요..
Checkable 커스텀 ConstraintLayout과 리스트뷰를 이용해서 구현했어요.
DELETE CONFIRM 버튼을 눌렀을 때 리스트뷰의 ChoiceMode가
CHOICE_MODE_NONE으로 바뀌면서 빨갛게 선택된 부분이 다시 흰색으로 바뀌게 하고싶어요.
메인 액티비티에서 clearchoices를 사용해도 흰색으로 돌아오지는 않더라구요.
listview를 구성하는 아이템인 커스텀 ConstraintLayout (ConstraintViewEventItem) 의 setChecked 함수가
색을 바꾸는 역할을 포함하고 있는데
이 것을 혹시 메인 액티비티에서 호출할 수 있는 방법이 있을까요?