Example usage for android.widget ListView ListView

List of usage examples for android.widget ListView ListView

Introduction

In this page you can find the example usage for android.widget ListView ListView.

Prototype

public ListView(Context context) 

Source Link

Usage

From source file:com.linkbubble.util.YouTubeEmbedHelper.java

AlertDialog getEmbedResultsDialog() {
    if (mEmbedInfo.size() > 0) {
        ListView listView = new ListView(mContext);
        listView.setAdapter(new EmbedItemAdapter());

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(listView);//from  w  w  w  .  ja va2s.com
        builder.setIcon(mYouTubeResolveInfo.loadIcon(mContext.getPackageManager()));
        builder.setTitle(R.string.title_youtube_embed_to_load);

        final AlertDialog alertDialog = builder.create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                EmbedInfo embedInfo = (EmbedInfo) view.getTag();
                if (embedInfo != null) {
                    loadYouTubeVideo(embedInfo.mId);
                }
                alertDialog.dismiss();
            }
        });

        return alertDialog;
    } else {
        final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
        alertDialog.setTitle(R.string.youtube_embed_error_title);
        alertDialog.setMessage(mContext.getString(R.string.youtube_embed_error_summary));
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,
                mContext.getResources().getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        alertDialog.dismiss();
                    }

                });
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        return alertDialog;
    }
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    //add pair to dashboard action
    case R.id.action_add:
        final CheckBoxListAdapter checkBoxListAdapter = new CheckBoxListAdapter(getActivity(),
                getResources().getStringArray(R.array.ExchangePairs), CheckBoxListAdapter.SettingsScope.PAIRS);
        ListView listView = new ListView(getActivity());
        listView.setAdapter(checkBoxListAdapter);
        new AlertDialog.Builder(getActivity()).setTitle(this.getString(R.string.SelectPairsPromptTitle))
                .setView(listView).setNeutralButton(getResources().getString(R.string.DialogSaveButton),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                checkBoxListAdapter.saveValuesToPreferences();
                                updateStorageWithTickers();
                                mTickersDashboardAdapter.update();
                                getActivity()
                                        .sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class));
                            }/*  w ww .  jav  a2s. c o m*/
                        })
                .show();
        break;
    //refresh dashboard action
    case R.id.action_refresh:
        mRefreshItem = item;
        mRefreshItem.setActionView(R.layout.progress_bar_action_view);
        mRefreshItem.expandActionView();
        getActivity().sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class));
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.github.michalbednarski.intentslab.editor.NewExtraPickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ListView listView = new ListView(getActivity());
    listView.setAdapter(mAdapter);/* w  ww.j  a va  2  s .c  o  m*/
    listView.setOnItemClickListener(this);
    Utils.fixListViewInDialogBackground(listView);
    return listView;
}

From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java

public static <D extends FhemDevice<D>> TypeHandler<D> handlerForSelectedOption(D device, Context context,
        final String option, final TargetStateSelectedCallback callback) {

    SetList setList = device.getSetList();
    final SetListValue setListValue = setList.get(option);

    final DeviceStateRequiringAdditionalInformation specialDeviceState = DeviceStateRequiringAdditionalInformation
            .deviceStateForFHEM(option);

    if (setListValue instanceof SetListSliderValue) {
        final SetListSliderValue sliderValue = (SetListSliderValue) setListValue;
        return new TypeHandler<D>() {
            private int dimProgress = 0;

            @Override/*from   w  ww .  j a va  2s. co  m*/
            public View getContentViewFor(Context context, D device) {
                TableLayout tableLayout = new TableLayout(context);
                int initialProgress = 0;
                if (device instanceof DimmableDevice) {
                    initialProgress = ((DimmableDevice) device).getDimPosition();
                }

                tableLayout.addView(new DeviceDimActionRowFullWidth<D>(initialProgress, sliderValue.getStart(),
                        sliderValue.getStep(), sliderValue.getStop(), null,
                        R.layout.device_detail_seekbarrow_full_width) {

                    @Override
                    public void onStopDim(Context context, D device, int progress) {
                        dimProgress = progress;
                    }

                    @Override
                    public String toDimUpdateText(D device, int progress) {
                        return null;
                    }
                }.createRow(LayoutInflater.from(context), device));
                return tableLayout;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                callback.onTargetStateSelected(option, "" + dimProgress, device, context);
                return true;
            }
        };
    } else if (setListValue instanceof SetListGroupValue) {
        final SetListGroupValue groupValue = (SetListGroupValue) setListValue;
        final List<String> groupStates = groupValue.getGroupStates();
        return new TypeHandler<D>() {

            @Override
            public View getContentViewFor(final Context context, final D device) {
                ListView listView = new ListView(context);
                listView.setAdapter(
                        new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, groupStates));
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                        String selection = groupStates.get(position);
                        callback.onTargetStateSelected(option, selection, device, context);
                        dialog.dismiss();
                    }
                });

                return listView;
            }

            @Override
            boolean requiresPositiveButton() {
                return false;
            }
        };
    } else if (specialDeviceState != null) {
        return new TypeHandler<D>() {

            private EditText editText;

            @Override
            public View getContentViewFor(Context context, D device) {
                editText = new EditText(context);
                return editText;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                Editable value = editText.getText();
                String text = value == null ? "" : value.toString();

                if (isValidAdditionalInformationValue(text, specialDeviceState)) {
                    callback.onTargetStateSelected(option, text, device, context);
                    return true;
                } else {
                    DialogUtil.showAlertDialog(context, R.string.error, R.string.invalidInput);
                    return false;
                }
            }
        };
    } else {
        callback.onTargetStateSelected(option, null, device, context);
        return null;
    }
}

From source file:com.reginald.swiperefresh.sample.ViewPagerDemoActivity.java

private void setupViewPagerViews() {
    mRecyclerView = new RecyclerView(this);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new GridLayoutManager(this, 2);

    mRecyclerView.setLayoutManager(mLayoutManager);

    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        Drawable mDivider;/*from   w ww . jav  a 2s  .  co m*/

        {
            final TypedArray a = ViewPagerDemoActivity.this
                    .obtainStyledAttributes(new int[] { android.R.attr.listDivider });
            mDivider = a.getDrawable(0);
            a.recycle();
        }

        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
            final int left = parent.getPaddingLeft();
            final int right = parent.getWidth() - parent.getPaddingRight();

            final int childCount = parent.getChildCount();
            for (int i = 0; i < childCount; i++) {
                final View child = parent.getChildAt(i);
                final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                final int top = child.getBottom() + params.bottomMargin;
                final int bottom = top + mDivider.getIntrinsicHeight();
                mDivider.setBounds(left, top, right, bottom);
                mDivider.draw(c);
            }
        }
    });

    // specify an adapter (see also next example)
    mRecyclerViewAdapter = new MyAdapter(Cheeses.randomList(LIST_ITEM_COUNT));
    mRecyclerView.setAdapter(mRecyclerViewAdapter);

    mListView = new ListView(this);
    mListAdapter = new ArrayAdapter<String>(this, R.layout.demo_list_item, R.id.item_text,
            Cheeses.randomList(LIST_ITEM_COUNT));

    mListView.setAdapter(mListAdapter);

    viewPagerViews.add(mListView);
    viewPagerViews.add(mRecyclerView);
    viewPagerTitles.add("ListView");
    viewPagerTitles.add("RecyclerView");
}

From source file:com.sentaroh.android.Utilities.ContextMenu.CustomContextMenuFragment.java

private void initViewWidget() {
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "initViewWidget");

    //      CommonDialog.setDlgBoxSizeCompact(mDialog);

    LinearLayout dlg_ll = new LinearLayout(getActivity());
    dlg_ll.setOrientation(LinearLayout.VERTICAL);
    TextView dlg_tv = new TextView(getActivity());
    dlg_tv.setBackgroundColor(Color.WHITE);
    dlg_tv.setTextColor(Color.BLACK);
    //        dlg_tv.setTextSize(32);
    dlg_tv.setGravity(android.view.Gravity.CENTER_VERTICAL | android.view.Gravity.CENTER_HORIZONTAL);

    ListView dlg_lv = new ListView(getActivity());
    dlg_lv.setBackgroundColor(Color.WHITE);

    dlg_ll.addView(dlg_tv);/*from   www  .jav  a2s .  c  o  m*/
    dlg_ll.addView(dlg_lv);

    mDialog.setContentView(dlg_ll);

    if (mDialogTitle.length() != 0) {
        dlg_tv.setText(mDialogTitle);
        dlg_tv.setVisibility(TextView.VISIBLE);
    } else
        dlg_tv.setVisibility(TextView.GONE);

    dlg_lv.setAdapter(mMenuAdapter);
    dlg_lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> items, View view, int idx, long id) {
            CustomContextMenuItem item = (CustomContextMenuItem) mMenuAdapter.getItem(idx);
            if (item.menu_enabled) {
                if (idx < mClickHandler.size()) {
                    mClickHandler.get(idx).onClick(item.text);
                }
                mFragment.dismiss();
            }
        }
    });
    dlg_lv.setScrollingCacheEnabled(false);
    dlg_lv.setScrollbarFadingEnabled(false);
    //      int[] colors = {0, 0xFFFF0000, 0}; // red for the example
    //      lv.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    dlg_lv.setDividerHeight(0);

}

From source file:de.vanita5.twittnuker.fragment.support.BaseSupportListFragment.java

/**
 * Provide default implementation to return a simple list view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a ListView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to
 * be shown when the list is empty.//from  w  ww  .  ja  v  a 2  s  . c  o m
 *
 * <p>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in
 * your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment. In particular, this is currently the only way
 * to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    final LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    final FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    final TextView tv = new TextView(getActivity());
    tv.setTextAppearance(context, ThemeUtils.getTextAppearanceLarge(context));
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setOnScrollListener(this);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:org.huxizhijian.hhcomicviewer.ui.main.MainActivity.java

private void showHistory() {
    if (mSharedPreferences == null) {
        mSharedPreferences = getSharedPreferences("history", Context.MODE_PRIVATE);
    }/*from w  ww. j  a  v a  2 s . co m*/
    String group = mSharedPreferences.getString("keys", "");
    if (!TextUtils.isEmpty(group)) {
        //?
        String[] history = group.split(":@");
        mSearchHistory = new ArrayList<>();
        if (history.length > 6) {
            //6???????6??
            for (int i = history.length - 1; i >= history.length - 6; i--) {
                mSearchHistory.add(history[i]);
            }
        } else {
            for (int i = history.length - 1; i >= 0; i--) {
                mSearchHistory.add(history[i]);
            }
        }
        if (mHistoryListView == null || mHistoryAdapter == null) {
            //?list view
            mHistoryListView = new ListView(MainActivity.this);
            mHistoryAdapter = new CommonAdapter<String>(MainActivity.this, mSearchHistory,
                    R.layout.item_search_history_white) {
                @Override
                public void convert(ViewHolder vh, String s) {
                    final TextView tv = vh.getView(R.id.tv_search_history);
                    tv.setText(s);
                    vh.getView(R.id.ll_search_history).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            String query = (String) tv.getText();
                            if (!TextUtils.isEmpty(query)) {
                                mBinding.searchView.setQuery(query, true);
                            }
                        }
                    });
                    vh.getView(R.id.btn_search_text_set).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mBinding.searchView.setQuery(tv.getText(), false);
                        }
                    });
                }
            };
            mHistoryListView.setBackgroundColor(R.color.white);
            mHistoryListView.setAdapter(mHistoryAdapter);
            if (mHistoryListView.getFooterViewsCount() == 0 && mSearchHistory.size() != 0) {
                final View footerView = LayoutInflater.from(MainActivity.this)
                        .inflate(R.layout.item_search_history_footview_white, mHistoryListView, false);
                footerView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SharedPreferences.Editor editor = mSharedPreferences.edit();
                        editor.putString("keys", "");
                        editor.apply();
                        Toast.makeText(MainActivity.this, R.string.clear_successful, Toast.LENGTH_SHORT).show();
                        mHistoryPop.dismiss();
                    }
                });
                mHistoryListView.addFooterView(footerView);
            }
            mHistoryListView.setDividerHeight(0);
            mHistoryListView.setPadding(0, 1, 0, 0);
        } else {
            mHistoryAdapter.setDatas(mSearchHistory);
            mHistoryAdapter.notifyDataSetChanged();
        }
        if (mHistoryPop == null) {
            //?popup window
            mHistoryPop = new PopupWindow(mHistoryListView, mBinding.searchView.getWidth(),
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            mHistoryPop.setFocusable(false);
            mHistoryPop.setOutsideTouchable(false);
        }
        mHistoryPop.showAsDropDown(mBinding.searchView);
    }
}

From source file:ru.example.sic.my_ads.activity.MainActivity.java

private void getSupport() {
    AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this, R.style.ThemeDialogCustom);
    alert.setTitle(getString(R.string.support_title));

    ListView supportSet = new ListView(MainActivity.this);
    String[] supportNames = getResources().getStringArray(R.array.supportType);
    ArrayAdapter adapter = new ArrayAdapter(MainActivity.this, R.layout.simple_list_item, supportNames);
    supportSet.setAdapter(adapter);/*w  w w.  j  a v  a 2  s .c  o  m*/
    supportSet.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            switch (i) {
            case 0: {
                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                final EditText editText = new EditText(MainActivity.this);
                alert.setTitle(getString(R.string.question_desc));
                alert.setView(editText);
                alert.setPositiveButton(getString(R.string.send), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Parse.Request.addAdReport(APP_SUPPORT, APP_SUPPORT_FROM_USER,
                                ParseUser.getCurrentUser(), APP_SUPPORT_QUESTION_FROM_USER,
                                editText.getText().toString());
                    }
                });
                alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
                alert.show();
                break;
            }
            case 1: {
                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                final EditText editText = new EditText(MainActivity.this);
                alert.setTitle(getString(R.string.error_desc));
                alert.setView(editText);
                alert.setPositiveButton(getString(R.string.send), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Parse.Request.addAdReport(APP_REPORT, APP_REPORT_FROM_USER, ParseUser.getCurrentUser(),
                                APP_REPORT_REPORT_FROM_USER, editText.getText().toString());
                    }
                });
                alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
                alert.show();
                break;
            }
            case 2: {
                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                final EditText editText = new EditText(MainActivity.this);
                alert.setTitle(getString(R.string.review_desc));
                alert.setView(editText);
                alert.setPositiveButton(getString(R.string.send), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Parse.Request.addAdReport(APP_REVIEW, APP_REVIEW_FROM_USER, ParseUser.getCurrentUser(),
                                APP_REVIEW_REVIEW_FROM_USER, editText.getText().toString());
                    }
                });
                alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
                alert.show();
                break;
            }
            }
        }
    });
    alert.setView(supportSet);

    alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });
    alert.show();
}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (backgroundColor == 0) {
        backgroundColor = darkTheme ? 0xFF424242 : 0xFFFFFFFF;
    }/*from   w w w . j  a  v a  2s .c o  m*/

    if (titleTextColor == 0) {
        titleTextColor = darkTheme ? 0xB3FFFFFF : 0x8A000000;
    }

    if (itemTextColor == 0) {
        itemTextColor = darkTheme ? 0xFFFFFFFF : 0xDE000000;
    }

    if (iconColor == 0) {
        iconColor = darkTheme ? 0xFFFFFFFF : 0x8A000000;
    }

    if (itemSelector == 0) {
        itemSelector = darkTheme ? R.drawable.selectable_dark : R.drawable.selectable_light;
    }

    Window window = getWindow();
    window.setWindowAnimations(R.style.DialogNoAnimation);
    setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (containerView == null) {
        containerView = new FrameLayout(getContext()) {
            @Override
            public boolean hasOverlappingRendering() {
                return false;
            }
        };
        if (Build.VERSION.SDK_INT >= 16) {
            containerView.setBackground(shadowDrawable);
        } else {
            containerView.setBackgroundDrawable(shadowDrawable);
        }
        containerView.setPadding(0, backgroundPaddingTop, 0, Utils.dp(getContext(), 8));
    }

    if (Build.VERSION.SDK_INT >= 21) {
        containerView.setFitsSystemWindows(true);
    }

    containerView.setVisibility(View.INVISIBLE);
    containerView.setBackgroundColor(backgroundColor);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;

    containerView.setLayoutParams(params);
    container.addView(containerView, 0);

    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }

        FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) containerView.getLayoutParams();
        params1.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params1.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params1.gravity = Gravity.START | Gravity.TOP;

        containerView.addView(customView, params1);
    } else {
        int topOffset = 0;

        if (titleText != null) {
            TextView titleTextView = new TextView(getContext());
            titleTextView.setLines(1);
            titleTextView.setMaxLines(1);
            titleTextView.setSingleLine(true);
            titleTextView.setText(titleText);
            titleTextView.setTextColor(titleTextColor);
            titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
            titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            titleTextView.setGravity(Gravity.CENTER_VERTICAL);

            FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    Utils.dp(getContext(), 56));
            params0.gravity = Gravity.START | Gravity.TOP;
            params0.leftMargin = Utils.dp(getContext(), 16);
            params0.rightMargin = Utils.dp(getContext(), 16);

            titleTextView.setLayoutParams(params0);
            containerView.addView(titleTextView);
            titleTextView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
            topOffset += 56;
        }

        BottomSheetAdapter adapter = new BottomSheetAdapter();

        if (mItems != null || mItemsRes != null) {
            if (contentType == LIST) {
                FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                params2.topMargin = Utils.dp(getContext(), topOffset);

                ListView listView = new ListView(getContext());
                listView.setSelector(itemSelector);
                listView.setDividerHeight(0);
                listView.setAdapter(adapter);
                listView.setDrawSelectorOnTop(true);
                listView.setVerticalScrollBarEnabled(false);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                listView.setLayoutParams(params2);
                containerView.addView(listView);
            } else if (contentType == GRID) {
                FrameLayout.LayoutParams params3 = new FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

                GridView gridView = new GridView(getContext());
                gridView.setSelector(itemSelector);
                gridView.setAdapter(adapter);
                gridView.setNumColumns(3);
                gridView.setVerticalScrollBarEnabled(false);
                gridView.setVerticalSpacing(Utils.dp(getContext(), 16));
                gridView.setPadding(Utils.dp(getContext(), 0), Utils.dp(getContext(), topOffset + 8),
                        Utils.dp(getContext(), 0), Utils.dp(getContext(), 16));
                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        dismissWithButtonClick(i);
                    }
                });
                gridView.setLayoutParams(params3);
                containerView.addView(gridView);
            }

            if (mItems != null) {
                for (int a = 0; a < mItems.length; a++) {
                    items.add(new Item(mItems[a], mIcons != null ? mIcons[a] : 0));
                }
            } else {
                for (int a = 0; a < mItemsRes.length; a++) {
                    items.add(new Item(getContext().getText(mItemsRes[a]), mIcons != null ? mIcons[a] : 0));
                }
            }

            adapter.notifyDataSetChanged();
        }
    }

    WindowManager.LayoutParams params4 = window.getAttributes();
    params4.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params4.gravity = Gravity.TOP | Gravity.START;
    params4.dimAmount = 0;
    params4.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    if (!focusable) {
        params4.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    }
    params4.height = ViewGroup.LayoutParams.MATCH_PARENT;
    window.setAttributes(params4);
}