Example usage for android.widget GridView setNumColumns

List of usage examples for android.widget GridView setNumColumns

Introduction

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

Prototype

public void setNumColumns(int numColumns) 

Source Link

Document

Set the number of columns in the grid

Usage

From source file:com.app.sample.chatting.data.emoji.EmojiPageFragment.java

@Override
protected void initWidget(View rootView) {
    super.initWidget(rootView);
    mPagerFace = (ViewPager) rootView.findViewById(R.id.frag_pager_face);
    pagePointLayout = (LinearLayout) rootView.findViewById(R.id.frag_point);

    int total = datas.size();
    int pages = total / ITEM_PAGE_COUNT + (total % ITEM_PAGE_COUNT == 0 ? 0 : 1);

    allPageViews = new GridView[pages];
    pointViews = new RadioButton[pages];

    for (int x = 0; x < pages; x++) {
        int start = x * ITEM_PAGE_COUNT;
        int end = (start + ITEM_PAGE_COUNT) > total ? total : (start + ITEM_PAGE_COUNT);
        final List<Emojicon> itemDatas = datas.subList(start, end);
        GridView view = new GridView(aty);
        EmojiAdapter faceAdapter = new EmojiAdapter(view, itemDatas);

        view.setNumColumns(7);
        view.setHorizontalSpacing(1);/* w ww  .  ja  v a2s  .  c o  m*/
        view.setVerticalSpacing(1);
        view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        view.setCacheColorHint(0);
        view.setPadding(2, 0, 2, 0);
        view.setBackgroundResource(android.R.color.transparent);
        view.setSelector(android.R.color.transparent);
        view.setVerticalScrollBarEnabled(false);
        view.setGravity(Gravity.CENTER);
        view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT));
        view.setAdapter(faceAdapter);

        view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    Emojicon emoji = itemDatas.get(position);
                    if (DisplayRules.isDeleteEmojicon(emoji)) {
                        listener.selectedBackSpace(emoji);
                    } else {
                        listener.selectedEmoji(emoji);
                    }
                }
            }
        });
        allPageViews[x] = view;

        RadioButton tip = new RadioButton(aty);
        tip.setBackgroundResource(R.drawable.selector_bg_tip);
        RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(8, 8);
        layoutParams.leftMargin = 10;
        pagePointLayout.addView(tip, layoutParams);
        if (x == 0) {
            tip.setChecked(true);
        }
        pointViews[x] = tip;
    }

    PagerAdapter facePagerAdapter = new FacePagerAdapter(allPageViews);
    mPagerFace.setAdapter(facePagerAdapter);
    mPagerFace.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int index) {
            pointViews[index].setChecked(true);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

From source file:com.app.sample.chatting.activity.chat.FacePageFragment.java

@Override
protected void initWidget(View rootView) {
    super.initWidget(rootView);
    mPagerFace = (ViewPager) rootView.findViewById(R.id.frag_pager_face);
    pagePointLayout = (LinearLayout) rootView.findViewById(R.id.frag_point);

    int total = datas.size();
    int pages = total / ITEM_PAGE_COUNT + (total % ITEM_PAGE_COUNT == 0 ? 0 : 1);

    allPageViews = new GridView[pages];
    pointViews = new RadioButton[pages];

    for (int x = 0; x < pages; x++) {
        int start = x * ITEM_PAGE_COUNT;
        int end = (start + ITEM_PAGE_COUNT) > total ? total : (start + ITEM_PAGE_COUNT);
        final List<Faceicon> itemDatas = datas.subList(start, end);
        GridView view = new GridView(aty);
        FaceAdapter faceAdapter = new FaceAdapter(view, itemDatas);
        view.setAdapter(faceAdapter);//w  w w. j  av  a 2  s. c  om

        view.setNumColumns(4);
        view.setBackgroundColor(Color.TRANSPARENT);
        view.setHorizontalSpacing(1);
        view.setVerticalSpacing(1);
        view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        view.setCacheColorHint(0);
        view.setVerticalScrollBarEnabled(false);
        view.setPadding(5, 0, 5, 0);
        view.setSelector(new ColorDrawable(Color.TRANSPARENT));
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        view.setGravity(Gravity.CENTER);

        view.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    listener.selectedFace(itemDatas.get(position));
                }
            }
        });
        allPageViews[x] = view;

        RadioButton tip = new RadioButton(aty);
        tip.setBackgroundResource(R.drawable.selector_bg_tip);
        RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(8, 8);
        layoutParams.leftMargin = 10;
        pagePointLayout.addView(tip, layoutParams);
        if (x == 0) {
            tip.setChecked(true);
        }
        pointViews[x] = tip;
    }

    PagerAdapter facePagerAdapter = new FacePagerAdapter(allPageViews);
    mPagerFace.setAdapter(facePagerAdapter);
    mPagerFace.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int index) {
            pointViews[index].setChecked(true);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.SpeakersGridFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final GridView gridView = getGridView();
    float sf = getResources().getDisplayMetrics().density;
    final int padding = (int) (5.0 * sf);
    final int spacing = (int) (20.0 * sf);

    gridView.setNumColumns(GridView.AUTO_FIT);
    gridView.setColumnWidth((int) (120 * sf));
    gridView.setStretchMode(GridView.STRETCH_SPACING);
    gridView.setVerticalFadingEdgeEnabled(true);
    gridView.setPadding(padding, padding, padding, padding);
    gridView.setHorizontalSpacing(spacing);
    gridView.setVerticalSpacing(spacing);
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GridView gridView = new GridView(this);
    setContentView(gridView);/*from   ww w.j a  v  a2  s.  c  o m*/
    String[] countries = new String[] { "China", "France", "Germany", "India", "Russia", "United Kingdom",
            "United States" };
    ListAdapter countryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
    gridView.setAdapter(countryAdapter);
    gridView.setNumColumns(2);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String s = ((TextView) view).getText() + " " + position;
            Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*//from   w ww  . ja  v  a  2 s  . c o m
       * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid,
            container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
       * Adjust the layout of the gridview to a square.
     *
     * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use
                * a hard coded value of 8 dip.
                *
                * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step
                * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value?
                */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid unnecessary updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:com.yahala.ui.Views.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        gridView.setColumnWidth(OSUtilities.dpf(45.0f));
        gridView.setNumColumns(-1);
        views.add(gridView);/*w w w.  j  ava  2s  .  c o m*/

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineColor(1711276032);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, OSUtilities.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:org.mareatlantica.ui.Views.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        gridView.setColumnWidth(AndroidUtilities.dpf(45.0f));
        gridView.setNumColumns(-1);
        views.add(gridView);// w  w w  .  j  a  v a  2s.  c  o  m

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(AndroidUtilities.dpf(2.0f));
    tabs.setUnderlineHeight(AndroidUtilities.dpf(2.0f));
    tabs.setUnderlineColor(1711276032);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(AndroidUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:ti.org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*// ww w . j  a  va2 s  .c o  m
     * TODO: build the layout programmatically to get rid of the resources,
     * so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater
            .inflate(RHelper.getLayout("org_dmfs_colorpickerdialog_palette_grid"), container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
     * Adjust the layout of the gridview to a square.
     * 
     * Inspired by Bill Lahti, see
     * http://blahti.wordpress.com/2012/07/23/three
     * -variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                 * TODO: getHorizontalSpacing() has been introduced
                 * in SDK level 16. We need to find a way to get get
                 * the actual spacing. Until then we use a hard
                 * coded value of 8 dip.
                 * 
                 * One way would be to use a dimension in the
                 * layout. That would allow us to resolve the
                 * dimension here. However, that would be one step
                 * away from a library without resource
                 * dependencies. Maybe there is an Android dimension
                 * resource with a reasonable value?
                 */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the
                    // entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the
            // entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid
            // unnecessary
            // updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:hoahong.facebook.messenger.ui.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        if (Utils.isTablet()) {
            gridView.setColumnWidth(Utils.dp(60));
        } else {/*from ww w .  j  a va  2s  . com*/
            gridView.setColumnWidth(Utils.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(Utils.dpf(2.0f));
    tabs.setUnderlineHeight(Utils.dpf(2.0f));
    tabs.setUnderlineColor(0x66000000);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(Utils.dp(61), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText("No recent");
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, Utils.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:me.cpwc.nibblegram.ui.Components.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {/* w  w  w .j a v a2  s .c  o  m*/
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundColor(0xff222222);
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineColor(0x66000000);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}