Android Selectable Adapter

package com.resturant.vivaatech.resturantapp.Adapters;

import android.util.SparseBooleanArray;
import android.widget.Filter;

import java.util.ArrayList;
import java.util.List;

 * Created by arifh_000 on 6/14/2016.
public abstract class SelectableAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
    private static final String TAG = SelectableAdapter.class.getSimpleName();

    private SparseBooleanArray selectedItems;

    public SelectableAdapter () {
        selectedItems = new SparseBooleanArray ();

     * Indicates if the item at position position is selected
     * @param position Position of the item to check
     * @return true if the item is selected, false otherwise
    public boolean isSelected(int position) {
        return getSelectedItems().contains(position);

     * Toggle the selection status of the item at a given position
     * @param position Position of the item to toggle the selection status for
    public void toggleSelection(int position) {
        if (selectedItems.get(position, false)) {
        } else {
            selectedItems.put(position, true);


     * Clear the selection status for all items
    public void clearSelection() {
        List<Integer> selection = getSelectedItems();
        for (Integer i : selection) {

     * Count the selected items
     * @return Selected items count
    public int getSelectedItemCount() {
        return selectedItems.size();

     * Indicates the list of selected items
     * @return List of selected items ids
    public List<Integer> getSelectedItems() {
        List<Integer> items = new ArrayList<>(selectedItems.size());
        for (int i = 0; i < selectedItems.size(); ++i) {
        return items;

How to prevent fragments from multiple instance

private void replaceFragment (Fragment fragment){
  String backStateName = fragment.getClass().getName();

  FragmentManager manager = getSupportFragmentManager();
  boolean fragmentPopped = manager.popBackStackImmediate (backStateName, 0);

  if (!fragmentPopped){ //fragment not in back stack, create it.
    FragmentTransaction ft = manager.beginTransaction();
    ft.replace(, fragment);

For my case:
I have declared it in  a class 

public static void replaceFragment (FragmentManager manager,Fragment fragment){

    String backStateName =  fragment.getClass().getName();
    String fragmentTag = backStateName;
    boolean fragmentPopped = manager.popBackStackImmediate(backStateName, 0);
    if (!fragmentPopped && manager.findFragmentByTag(fragmentTag) == null) { //fragment not in back stack, create it.
        FragmentTransaction ft = manager.beginTransaction();
        ft.replace(, fragment, fragmentTag);


and used it as :

Functions.replaceFragment(getFragmentManager(),new OrderFoodTypeFragment());

Reference :

How to Add customize Android DialogFragment

public class ColorDialogFragment extends SherlockDialogFragment {

    public ColorDialogFragment() {
    //You need to provide a default constructor

    public View onCreateView(LayoutInflater inflater, 
                     ViewGroup container,
                     Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.dialog_color_picker, container);
    // R.layout.dialog_color_picker is the custom layout of my dialog
    WindowManager.LayoutParams wmlp = getDialog().getWindow().getAttributes();
    wmlp.gravity = Gravity.LEFT;
    return view;

    public void onCreate(Bundle savedInstanceState) {
    // this setStyle is VERY important.
    // STYLE_NO_FRAME means that I will provide my own layout and style for the whole dialog
    // so for example the size of the default dialog will not get in my way
    // the style extends the default one. see bellow.        


<style name="colorPickerStyle" parent="Theme.Sherlock.Light.Dialog">
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:cacheColorHint">@android:color/transparent</item>
    <item name="android:windowBackground">@android:color/transparent</item>
i Have done it as :

<style name="colorPickerStyle" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:cacheColorHint">@android:color/white</item>
    <item name="android:windowBackground">@android:color/white</item>