In my OnItemLongClick
, I need to set my visibility of checkbox from GONE
to VISIBLE
.
bookList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (!inSelectMode) {
inSelectMode = true;
myAdapter.setCheckMode(true);
CheckBox checkBox = view.findViewById(R.id.checkBox);
if (checkBox.isEnabled()) {
checkBox.performClick();
}
int books = myAdapter.getCheckCount();
// totalSelected.setVisibility(View.VISIBLE);
// totalSelected
// .setText("You've selected " + ((books == 0) ? "no" : Integer.toString(books)) + ((books == 1) ? " book" : " books"));
}
return true;
}
});
Once I uncomment the totalSelected.setVisibility()
the method setCheckMode()
which contains the checkBox.setVisibility()
doesn't work. There's no error, it just doesnt do anything.
totalSelected
is a textView
from my activity and checkBox
is a CheckBox
inside the row layout of my ListView
. Is there some kind of problem when using these 2 views together(since one is in my activity.xml and the other is in my rowlayout.xml) ? If so How can I solve this issue?
relevant parts of my Adapter:
public void setCheckMode(boolean checkMode) {
Log.d("setCheckMode :",checkMode?" true":" false");
this.isCheckMode = checkMode;
notifyDataSetChanged();
if(!checkMode){
checker.isAnyChecked(false);
checkCount = 0;
}
}
-
public void bindView(View v, Context context, Cursor cursor) {
Log.d("bindView :", cursor.getString(1));
final CheckBox checkBox = (CheckBox) v.findViewById(R.id.checkBox);
Log.d("BindView isCheckMode?:",isCheckMode ? "true" : "false");
if(isCheckMode){
checkBox.setVisibility(View.VISIBLE);
Log.d("checkbox visibility :","visible");
}
else{
checkBox.setVisibility(View.GONE);
Log.d("checkbox visibility","gone");
}
if (!isCheckMode){
Log.d("setChecked :","false");
checkBox.setChecked(false);
}
totalSelected
?myAdapter.getCheckCount()
.myAdapter.getCheckCount()
seems to not affect the checkbox visibility