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.bilibili.socialize.share.utils.selector.BaseSharePlatformSelector.java

protected static GridView createShareGridView(final Context context,
        AdapterView.OnItemClickListener onItemClickListener) {
    GridView grid = new GridView(context);
    ListAdapter adapter = new ArrayAdapter<ShareTarget>(context, 0, shareTargets) {
        // no need scroll
        @Override/*from w w w .jav  a  2s . c o  m*/
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bili_socialize_shareboard_item, parent, false);
            view.setBackgroundDrawable(null);
            ImageView image = (ImageView) view.findViewById(R.id.bili_socialize_shareboard_image);
            TextView platform = (TextView) view.findViewById(R.id.bili_socialize_shareboard_pltform_name);

            ShareTarget target = getItem(position);
            image.setImageResource(target.iconId);
            platform.setText(target.titleId);
            return view;
        }
    };
    grid.setNumColumns(-1);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.bili_socialize_shareboard_size));
    grid.setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
    grid.setSelector(R.drawable.bili_socialize_selector_item_background);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(onItemClickListener);
    return grid;
}

From source file:com.javielinux.dialogs.SelectIconDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int title = R.string.select_icon;

    final ArrayList<Entity> icons = DataFramework.getInstance().getEntityList("icons");
    ArrayList<Integer> resources = new ArrayList<Integer>();

    for (Entity icon : icons) {
        resources.add(getResources().getIdentifier(
                DataFramework.getInstance().getPackage() + ":drawable/" + icon.getString("icon"), null, null));
    }/*from   www.  j av a 2  s. c  o m*/

    ImageResourcesAdapter adapter = new ImageResourcesAdapter(getActivity(), resources);

    GridView gridView = new GridView(getActivity());
    gridView.setNumColumns(3);
    gridView.setPadding(5, 5, 5, 5);
    gridView.setVerticalSpacing(5);
    gridView.setGravity(Gravity.CENTER);
    gridView.setAdapter(adapter);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
            if (selectIconListener != null) {
                selectIconListener.onSelectIcon(icons.get(pos).getId());
            }
            dismiss();
        }
    });

    return new AlertDialog.Builder(getActivity()).setTitle(title).setView(gridView).create();
}

From source file:com.chale22.ico01.iconfragment.IconFragmentGames.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.icon_main, container, false);
    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    GridView gridview = (GridView) view.findViewById(R.id.icon_grid);
    gridview.setNumColumns(4);
    gridview.setColumnWidth(iconSize);//  w w w. ja va 2 s  . c  o  m
    gridview.setStretchMode(GridView.STRETCH_SPACING_UNIFORM);
    gridview.setVerticalSpacing(iconSize / 2);
    gridview.setOnItemClickListener(this);
    gridview.setAdapter(new IconAdapter(getActivity(), iconSize));
    gridview.setOnItemClickListener(this);
    CONTENT_URI = Uri.parse("content://" + iconsProvider.class.getCanonicalName());
    return view;

}

From source file:it.gcaliendo.elytheme.iconfragment.IconFragmentGames.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.icon_main, container, false);
    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    GridView gridview = (GridView) view.findViewById(R.id.icon_grid);
    gridview.setNumColumns(4);
    gridview.setColumnWidth(iconSize);/* ww w.j  a  v a2 s.c o m*/
    gridview.setStretchMode(GridView.STRETCH_SPACING_UNIFORM);
    gridview.setVerticalSpacing(iconSize / 2);
    gridview.setOnItemClickListener(this);
    gridview.setAdapter(new IconAdapter(getActivity(), iconSize));
    gridview.setOnItemClickListener(this);
    CONTENT_URI = Uri.parse("content://" + IconsProvider.class.getCanonicalName());
    return view;

}

From source file:com.github.yuukis.businessmap.app.ContactsActionFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mContact = (ContactsItem) getArguments().getSerializable(KEY_CONTACTS);

    MenuAdapter adapter = new MenuAdapter(getActivity(), R.layout.gridview_contents, ACTION_ITEMS);
    int columns = getResources().getInteger(R.integer.gridview_columns);
    GridView gridView = new GridView(getActivity());
    gridView.setNumColumns(columns);
    gridView.setAdapter(adapter);//ww w. j a  va  2  s  . co m
    gridView.setOnItemClickListener(this);
    gridView.setBackgroundColor(Color.WHITE);
    String title = mContact.getName();

    return new AlertDialog.Builder(getActivity()).setTitle(title).setView(gridView)
            .setNegativeButton(android.R.string.cancel, null).create();
}

From source file:es.esy.vivekrajendran.news.fragments.ProviderFragment.java

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

    String url = "https://newsapi.org/v1/sources?apikey=6e661062a47d4eac83dc8a7ee0dcc96b";
    //        getData(url);
    providerAdapter = new ProviderAdapter(getContext(), null);
    GridView gridView = (GridView) view.findViewById(R.id.gv_providers_fragment);
    gridView.setNumColumns(2);
    gridView.setAdapter(providerAdapter);

    getLoaderManager().initLoader(PROVIDER_LOADER, null, this);

}

From source file:es.esy.vivekrajendran.news.fragments.ImageFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    GridView gridView = (GridView) view.findViewById(R.id.lv_frag_images);
    imageAdapter = new Adapter(getActivity(), null);
    gridView.setNumColumns(4);
    gridView.setAdapter(imageAdapter);//from w  w w  . ja va  2  s  .c  o m
    getData(BaseUrl + query);
    getLoaderManager().initLoader(IMAGE_LOADER, null, this);

    FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab_frag_images);
    if (!NetworkChecker.getInstance(getContext()).isNetworkAvailable())
        fab.setVisibility(View.GONE);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
}

From source file:edu.rowan.app.fragments.HomescreenFragment.java

/**
 * Construct the view for this fragment.
 * The core layout of this fragment is a CarouselView and grid of available buttons
 *///from   w  w  w.  jav  a 2 s .  c o  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // hide actionbar loading indicator TODO: move this elsewhere
    activity.showLoading(false);

    View view = inflater.inflate(R.layout.activity_main, container, false);
    RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.mainLayout);
    layout.setPadding(0, 20, 0, 0);

    CarouselView rowanFeatures = new CarouselView(inflater.getContext());
    // set view Id so that relativeLayout can position. Without an Id relativeLayout doesn't work
    rowanFeatures.setId(2342343);
    layout.addView(rowanFeatures);
    setTouchListener(rowanFeatures);

    GridView grid = new GridView(inflater.getContext());
    grid.setOnItemClickListener(this);
    grid.setNumColumns(3);
    grid.setVerticalSpacing(20);
    grid.setAdapter(new RowanAdapter());
    RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    gridParams.addRule(RelativeLayout.BELOW, rowanFeatures.getId());
    gridParams.topMargin = 20;
    layout.addView(grid, gridParams);

    return view;
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentButton.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_button, container, false);

    Bundle args = getArguments();//from   ww  w .  ja v a2 s. c  om
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    // The activity must support a standard OnClickListener.
    final MainActivity mainActivity = (MainActivity) getActivity();
    final Context context = mainActivity;

    players = mainActivity.getPlayers();
    if (players != null) {
        players.addListener(mPlayersListener);
    }

    // final int index = args.getInt(ARG_INDEX);
    final String tabSpec = args.getString(ARG_TAB_SPEC);

    try {
        JSONObject jsonTab = new JSONObject(tabSpec);

        final String tabName = jsonTab.optString(JsonSpec.TAB_NAME, JsonSpec.DEFAULT_TAB_NAME);
        if (!TextUtils.isEmpty(tabName)) {
            TextView tv = (TextView) rootView.findViewById(R.id.text_view_name);
            tv.setText(tabName);
        }

        tabLayout = (LinearLayout) rootView;

        JSONArray jsonSections = jsonTab.getJSONArray(JsonSpec.SECTIONS_KEY);
        for (int i = 0; i < jsonSections.length(); i++) {
            JSONObject jsonSection = jsonSections.getJSONObject(i);

            LinearLayout sectionLayout = new LinearLayout(context);
            sectionLayout.setOrientation(LinearLayout.VERTICAL);
            tabLayout.addView(sectionLayout);

            // If a section is named, label it.
            final String sectionName = jsonSection.optString(JsonSpec.SECTION_NAME,
                    JsonSpec.DEFAULT_SECTION_NAME);
            if (!TextUtils.isEmpty(sectionName)) {
                TextView textView = new TextView(context);
                textView.setText(sectionName);
                sectionLayout.addView(textView);
            }

            int numColumns = jsonSection.optInt(JsonSpec.SECTION_COLUMNS, JsonSpec.DEFAULT_SECTION_COLUMNS);

            List<View> buttonViews = new LinkedList<View>();

            JSONArray buttons = jsonSection.getJSONArray(JsonSpec.BUTTONS_KEY);
            for (int k = 0; k < buttons.length(); k++) {
                JSONObject jsonButton = buttons.getJSONObject(k);

                ScoreButton buttonView = new ScoreButton(context);
                buttonView.setButtonSpec(jsonButton);
                buttonView.setOnClickListener(mainActivity.getScoreClickListener());

                // Add the button to the section.
                buttonViews.add(buttonView);
            }

            GridView gridView = new GridView(context);
            gridView.setNumColumns(numColumns);
            gridView.setAdapter(new ViewAdapter(context, buttonViews));
            sectionLayout.addView(gridView);
        }
    } catch (JSONException e) {
        Log.th(TAG, e, "onCreateView: failed to parse JSON");
    }

    updateUi();

    return rootView;
}

From source file:com.lm.im_huanxin.emoji.EmojiPageFragment.java

protected void initWidget(View 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);//from www . j a va 2 s .c om
        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) {
        }
    });
}