Package eltos.simpledialogfragment.list
Class CustomListDialog<This extends CustomListDialog<This>>
java.lang.Object
androidx.fragment.app.Fragment
androidx.fragment.app.DialogFragment
eltos.simpledialogfragment.SimpleDialog<This>
eltos.simpledialogfragment.CustomViewDialog<This>
eltos.simpledialogfragment.list.CustomListDialog<This>
- All Implemented Interfaces:
android.content.ComponentCallbacks
,android.content.DialogInterface.OnCancelListener
,android.content.DialogInterface.OnDismissListener
,android.view.View.OnCreateContextMenuListener
,android.widget.AdapterView.OnItemClickListener
,android.widget.AdapterView.OnItemLongClickListener
,androidx.activity.result.ActivityResultCaller
,androidx.lifecycle.HasDefaultViewModelProviderFactory
,androidx.lifecycle.LifecycleOwner
,androidx.lifecycle.ViewModelStoreOwner
,androidx.savedstate.SavedStateRegistryOwner
- Direct Known Subclasses:
SimpleColorDialog
,SimpleListDialog
public abstract class CustomListDialog<This extends CustomListDialog<This>>
extends CustomViewDialog<This>
implements android.widget.AdapterView.OnItemClickListener, android.widget.AdapterView.OnItemLongClickListener
A dialog that displays a list of items.
MULTI_CHOICE and SINGLE_CHOICE modes are supported.
Specify your custom adapter
Result:
SELECTED_POSITIONS Integer ArrayList selected item positions
SELECTED_IDS Long[] selected item ids
In SINGLE_CHOICE and SINGLE_CHOICE_DIRECT mode also:
SELECTED_SINGLE_POSITION int selected item position
SELECTED_SINGLE_ID long selected item id
Created by eltos on 02.01.2017.
-
Nested Class Summary
Nested classes/interfaces inherited from class eltos.simpledialogfragment.SimpleDialog
SimpleDialog.OnDialogResultListener
Nested classes/interfaces inherited from class androidx.fragment.app.Fragment
androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected AdvancedAdapter<?>
protected android.widget.EditText
protected android.widget.AbsListView
static final int
static final int
static final String
Key for a long[] returned byonResult(int)
static final String
Key for an ArrayList<Integer> returned byonResult(int)
static final String
Key for a long returned byonResult(int)
in single choice modestatic final String
Key for an int returned byonResult(int)
in single choice modestatic final int
static final int
protected static final String
Fields inherited from class eltos.simpledialogfragment.SimpleDialog
BUNDLE, CANCELABLE, FULLSCREEN, HTML, ICON_RESOURCE, MESSAGE, NEGATIVE_BUTTON_TEXT, NEUTRAL_BUTTON_TEXT, POSITIVE_BUTTON_TEXT, THEME, TITLE
Fields inherited from class androidx.fragment.app.DialogFragment
STYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMAL
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchoiceIdPreset
(long id) Sets the initially checked item by its idchoiceIdPreset
(long[] ids) Sets the initially checked items by their idschoiceIdPreset
(List<Long> ids) Sets the initially checked items by their idschoiceMax
(int count) Sets the maximum allowed choices for the positive button to become enabledchoiceMin
(int count) Sets the minimum required choices for the positive button to become enabledchoiceMode
(int mode) Sets the list choice modechoicePreset
(int position) Sets the initially checked item positionchoicePreset
(int[] positions) Sets the initially checked item positionschoicePreset
(List<Integer> positions) Sets the initially checked item positionsdivider
(boolean show) Sets the visibility of the divideremptyText
(int titleResourceId) Sets a string to be displayed if no items are currently visibleemptyText
(CharSequence title) Sets a string to be displayed if no items are currently visiblefilterable
(boolean enabled) If set to true, show an input field at the to of the list and allow the user to filter the listprotected android.widget.AbsListView
grid()
Change the list into a grid list view (grid mode)gridColumnWidth
(int columnWidthDimenResId) Specifies the column with of this grid view (only if in grid mode)gridNumColumn
(int numColumns) Specifies the number of columns of this grid view (only if in grid mode)protected void
protected abstract AdvancedAdapter
Overwrite this method to provide a custom adapterprotected android.view.View
onCreateContentView
(android.os.Bundle savedInstanceState) Inflate your custom view here.protected void
Overwrite this method to take action once the dialog is shown such as settings an input focus, showing the keyboard or setting the initial positiveButtonStatevoid
onItemClick
(android.widget.AdapterView<?> parent, android.view.View view, int position, long id) Callback method to be invoked when an item in this AdapterView has been clicked.boolean
onItemLongClick
(android.widget.AdapterView<?> parent, android.view.View view, int position, long id) Callback method to be invoked when an item in this view has been clicked and held.protected android.os.Bundle
onResult
(int which) Overwrite this method to provide additional results from your custom view to be passed to theSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
void
onSaveInstanceState
(android.os.Bundle outState) pos
(int positiveButtonResourceId) Sets this dialogs positive button textpos
(CharSequence positiveButton) Sets this dialogs positive button textprotected void
Methods inherited from class eltos.simpledialogfragment.CustomViewDialog
acceptsPositiveButtonPress, build, callResultListener, extractContentView, inflate, inflate, onCreate, onCreateDialog, onNegativeButtonClick, onNeutralButtonClick, onPositiveButtonClick, pressPositiveButton, setNegativeButtonEnabled, setNeutralButtonEnabled, setPositiveButtonEnabled
Methods inherited from class eltos.simpledialogfragment.SimpleDialog
cancelable, extra, fullscreen, fullscreen, getArgs, getArgString, getContext, getExtras, getMessage, getTitle, icon, isCancelable, msg, msg, msgHtml, msgHtml, neg, neg, neg, neut, neut, neut, onCancel, onDestroyView, setArg, setArg, setArg, setArg, setButtonClickListener, setButtonEnabled, show, show, show, show, show, show, show, show, showKeyboard, theme, title, title
Methods inherited from class androidx.fragment.app.DialogFragment
dismiss, dismissAllowingStateLoss, getDialog, getShowsDialog, getTheme, onAttach, onDetach, onDismiss, onGetLayoutInflater, onStart, onStop, onViewStateRestored, requireDialog, setCancelable, setShowsDialog, setStyle, setupDialog, showNow
Methods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onViewCreated, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface androidx.lifecycle.HasDefaultViewModelProviderFactory
getDefaultViewModelCreationExtras
-
Field Details
-
TAG
- See Also:
-
NO_CHOICE
public static final int NO_CHOICE- See Also:
-
SINGLE_CHOICE
public static final int SINGLE_CHOICE- See Also:
-
SINGLE_CHOICE_DIRECT
public static final int SINGLE_CHOICE_DIRECT- See Also:
-
MULTI_CHOICE
public static final int MULTI_CHOICE- See Also:
-
SELECTED_IDS
Key for a long[] returned byonResult(int)
- See Also:
-
SELECTED_POSITIONS
Key for an ArrayList<Integer> returned byonResult(int)
- See Also:
-
SELECTED_SINGLE_ID
Key for a long returned byonResult(int)
in single choice mode- See Also:
-
SELECTED_SINGLE_POSITION
Key for an int returned byonResult(int)
in single choice mode- See Also:
-
CHOICE_MODE
- See Also:
-
CHOICE_MIN_COUNT
- See Also:
-
CHOICE_MAX_COUNT
- See Also:
-
INITIALLY_CHECKED_POSITIONS
- See Also:
-
INITIALLY_CHECKED_IDS
- See Also:
-
mListView
protected android.widget.AbsListView mListView -
mAdapter
-
mFilterEditText
protected android.widget.EditText mFilterEditText
-
-
Constructor Details
-
CustomListDialog
public CustomListDialog()
-
-
Method Details
-
onCreateAdapter
Overwrite this method to provide a custom adapter- Returns:
- the ListAdapter to use
-
choiceMode
Sets the list choice mode- Parameters:
mode
- one ofNO_CHOICE
,SINGLE_CHOICE
,SINGLE_CHOICE_DIRECT
orMULTI_CHOICE
- Returns:
- this instance
-
choiceMin
Sets the minimum required choices for the positive button to become enabled- Parameters:
count
- the minimum required choices- Returns:
- this instance
-
choiceMax
Sets the maximum allowed choices for the positive button to become enabled- Parameters:
count
- the maximum allowed choices- Returns:
- this instance
-
choicePreset
Sets the initially checked item positions- Parameters:
positions
- the initially checked positions- Returns:
- this instance
-
choicePreset
Sets the initially checked item positions- Parameters:
positions
- the initially checked positions- Returns:
- this instance
-
choicePreset
Sets the initially checked item position- Parameters:
position
- the initially checked position- Returns:
- this instance
-
choiceIdPreset
Sets the initially checked items by their ids- Parameters:
ids
- the initially checked item ids- Returns:
- this instance
-
choiceIdPreset
Sets the initially checked items by their ids- Parameters:
ids
- the initially checked item ids- Returns:
- this instance
-
choiceIdPreset
Sets the initially checked item by its id- Parameters:
id
- the initially checked item id- Returns:
- this instance
-
grid
Change the list into a grid list view (grid mode)- Returns:
- this instance
-
gridNumColumn
Specifies the number of columns of this grid view (only if in grid mode)- Parameters:
numColumns
- the number of columns- Returns:
- this instance
-
gridColumnWidth
Specifies the column with of this grid view (only if in grid mode)- Parameters:
columnWidthDimenResId
- the with as an android dimension resource identifier- Returns:
- this instance
-
divider
Sets the visibility of the divider- Parameters:
show
- whether to display a divider or not- Returns:
- this instance
-
filterable
If set to true, show an input field at the to of the list and allow the user to filter the list- Parameters:
enabled
- whether to allow filtering or not- Returns:
- this instance
-
emptyText
Sets a string to be displayed if no items are currently visible- Parameters:
title
- the string to be displayed- Returns:
- this instance
-
emptyText
Sets a string to be displayed if no items are currently visible- Parameters:
titleResourceId
- the android string resource to be displayed- Returns:
- this instance
-
pos
Description copied from class:SimpleDialog
Sets this dialogs positive button text- Overrides:
pos
in classSimpleDialog<This extends CustomListDialog<This>>
- Parameters:
positiveButton
- the text as string- Returns:
- this instance
-
pos
Description copied from class:SimpleDialog
Sets this dialogs positive button text- Overrides:
pos
in classSimpleDialog<This extends CustomListDialog<This>>
- Parameters:
positiveButtonResourceId
- the text as android string resource- Returns:
- this instance
-
onItemClick
public void onItemClick(android.widget.AdapterView<?> parent, android.view.View view, int position, long id) Callback method to be invoked when an item in this AdapterView has been clicked. Implementers can call Adapter#getItem(position) if they need to access the data associated with the selected item.- Specified by:
onItemClick
in interfaceandroid.widget.AdapterView.OnItemClickListener
- Parameters:
parent
- The AdapterView where the click happened.view
- The view within the AdapterView that was clicked (this will be a view provided by the adapter)position
- The position of the view in the adapter.id
- The row id of the item that was clicked.
-
onItemLongClick
public boolean onItemLongClick(android.widget.AdapterView<?> parent, android.view.View view, int position, long id) Callback method to be invoked when an item in this view has been clicked and held. Implementers can call Adapter#getItem(position) if they need to access the data associated with the selected item.- Specified by:
onItemLongClick
in interfaceandroid.widget.AdapterView.OnItemLongClickListener
- Parameters:
parent
- The AbsListView where the click happenedview
- The view within the AbsListView that was clickedposition
- The position of the view in the listid
- The row id of the item that was clicked- Returns:
- true if the callback consumed the long click, false otherwise
-
onCreateContentView
protected android.view.View onCreateContentView(android.os.Bundle savedInstanceState) Description copied from class:CustomViewDialog
Inflate your custom view here.- Specified by:
onCreateContentView
in classCustomViewDialog<This extends CustomListDialog<This>>
- Parameters:
savedInstanceState
- The last saved instance state of the Fragment, or null if this fragment is created for the first time.- Returns:
- Return a new View to be displayed by the Fragment.
-
getListView
protected android.widget.AbsListView getListView() -
notifyDataSetChanged
protected void notifyDataSetChanged() -
onDialogShown
protected void onDialogShown()Description copied from class:CustomViewDialog
Overwrite this method to take action once the dialog is shown such as settings an input focus, showing the keyboard or setting the initial positiveButtonState- Overrides:
onDialogShown
in classCustomViewDialog<This extends CustomListDialog<This>>
-
updatePosButton
protected void updatePosButton() -
onResult
protected android.os.Bundle onResult(int which) Description copied from class:CustomViewDialog
Overwrite this method to provide additional results from your custom view to be passed to theSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Overrides:
onResult
in classCustomViewDialog<This extends CustomListDialog<This>>
- Parameters:
which
- seeSimpleDialog.OnDialogResultListener
- Returns:
- the bundle to merge with the results or null
-
onSaveInstanceState
public void onSaveInstanceState(android.os.Bundle outState) - Overrides:
onSaveInstanceState
in classandroidx.fragment.app.DialogFragment
-