Code example for GridView

Methods: setPaddingsetFastScrollEnabledsetAdaptersetColumnWidthsetHorizontalSpacingsetNumColumnssetStretchModesetVerticalSpacing, setOnItemClickListener

0
        ActivityManager activityManager =
                (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        int iconSize = activityManager.getLauncherLargeIconSize();
        final String pkgName = getIntent().getStringExtra("package");
 
        GridView gridview = new GridView(this);
        gridview.setNumColumns(GridView.AUTO_FIT);
        gridview.setHorizontalSpacing(40);
        gridview.setVerticalSpacing(40);
        gridview.setPadding(20, 20, 20, 0);
        gridview.setFastScrollEnabled(true);
        gridview.setColumnWidth(iconSize);
        gridview.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
 
        gridview.setAdapter(new ImageAdapter(this, pkgName));
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override 
            public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
                Intent in = new Intent();
                DrawableInfo d = (DrawableInfo) adapterView.getAdapter().getItem(position);
                in.putExtra(SELECTED_RESOURCE_EXTRA, pkgName + "|" + d.resource_name);
Connect your IDE to all the code out there  Get Codota for Java