Closed saket closed 1 year ago
This appears to be a result of setting the selection mode as ListView.CHOICE_MODE_MULTIPLE_MODAL
without registering a MultiChoiceModeListener
with a call to AbsHListView.setMultiChoiceModeListener()
. The code seems to suggest that an IllegalArgumentException
should be thrown with a message indicating that a callback is required, but the condition preceding its throwing evaluates to false and a wrapper of a null callback gets passed up the view hierarchy until it's called, at which point it throws a NullPointerException
. An easy fix is to simply register a callback.
public void setItemChecked( int position, boolean value ) {
if ( mChoiceMode == ListView.CHOICE_MODE_NONE ) {
return;
}
// Start selection mode if needed. We don't need to if we're unchecking something.
if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
if ( value && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null ) {
if ( mMultiChoiceModeCallback == null ||
!((MultiChoiceModeWrapper)mMultiChoiceModeCallback).hasWrappedCallback() ) {
throw new IllegalStateException( "AbsListView: attempted to start selection mode " +
"for CHOICE_MODE_MULTIPLE_MODAL but no choice mode callback was " +
"supplied. Call setMultiChoiceModeListener to set a callback." );
}
mChoiceActionMode = startActionMode( (MultiChoiceModeWrapper)mMultiChoiceModeCallback );
}
}
...
The selection mode is set ListView.CHOICE_MODE_MULTIPLE_MODAL
by default. I think this should be removed because the developer isn't aware of this.
you could just set the HListView ListView.CHOICE_MODE_SINGLE
to skip the exception.
First of all, thank you so much for this fantastic custom ListView.
Everything is working perfectly, except for one thing. Long-pressing on a child is throwing NullPointerExceptions. Here's the stack-trace:
The issue is happening at line #2572 of AbsHListView.java.
Current workaround: By setting the choice mode of HListView to anything other than
ListView.CHOICE_MODE_MULTIPLE_MODAL
so that the line where the NPE is being thrown is never reached.