Example usage for android.widget GridView setAdapter

List of usage examples for android.widget GridView setAdapter

Introduction

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

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this GridView.

Usage

From source file:net.logomancy.diedroid.StatsFragment.java

public void onClick(View v) {
    Integer numStats = 6; // we're rolling 6 stats
    Integer[] diceTemp, stats;//  w ww.ja va2 s.c o  m
    Integer temp;
    int i;
    stats = new Integer[numStats]; // initialize stats array

    // now we roll stats based on what method we want
    switch (rollType) {
    case 1: // Straight 3d6
        dice.Quantity = 3;
        dice.Sides = 6;
        for (i = 0; i < numStats;) {
            temp = dice.roll().total;
            if (temp >= dropThreshold) {
                stats[i] = temp;
                i++;
            }
        }
        break;
    case 0: // 4d6, drop the lowest
        dice.Quantity = 1;
        dice.Sides = 6;
        diceTemp = new Integer[4];
        for (i = 0; i < numStats;) {
            diceTemp[0] = dice.roll().total;
            diceTemp[1] = dice.roll().total;
            diceTemp[2] = dice.roll().total;
            diceTemp[3] = dice.roll().total;
            Arrays.sort(diceTemp);
            // since the array is now sorted in ascending numerical order, dice[0] is the lowest
            temp = diceTemp[1] + diceTemp[2] + diceTemp[3];
            if (temp >= dropThreshold) {
                stats[i] = temp;
                i++;
            }
        }
        break;
    case 2: // d6 + 14
        dice.Quantity = 1;
        dice.Sides = 6;
        dice.Adder = 14;
        for (i = 0; i < numStats;) {
            temp = dice.roll().total;
            if (temp >= dropThreshold) {
                stats[i] = temp;
                i++;
            }
        }
        break;
    }

    // capture the GridView and attach an adapter with our stats in it
    GridView statsGrid = (GridView) getView().findViewById(R.id.statsResultsGrid);
    statsGrid.setAdapter(new ArrayAdapter<Integer>(getView().getContext(), R.layout.diegridsquare, stats));
}

From source file:view.EmojiconGridFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
    Bundle bundle = getArguments();//from  w  ww .  jav  a2  s  .  com

    mData = People.DATA;
    mUseSystemDefault = false;

    gridView.setAdapter(new EmojiAdapter(view.getContext(), mData, mUseSystemDefault));
    gridView.setOnItemClickListener(this);
}

From source file:edu.cwru.apo.Home.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_screen);

    GridView gridview = (GridView) findViewById(R.id.gridView);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(this);

}

From source file:com.networking.fragments.ImageGridFragment.java

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

    final View v = inflater.inflate(R.layout.image_grid_fragment, container, false);
    final GridView mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(this);
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override/*from  w w w  .ja va2  s. co  m*/
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    return v;
}

From source file:com.example.tony.popularmovie.MainActivityFragment.java

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

    mMoviePosterAdapter = new MoviePosterAdapter(getActivity(), null, 0);

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

    GridView gridview = (GridView) rootView.findViewById(R.id.gridview);
    gridview.setAdapter(mMoviePosterAdapter);

    gridview.setOnItemClickListener(new OnItemClickListener() {
        @Override/*w  w  w .  j ava2  s.  c  o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            String movieId = null;
            if (cursor.moveToPosition(position)) {
                movieId = cursor.getString(cursor.getColumnIndex(MovieContract.PopularEntry.COLUMN_MOVIE_ID));
            }

            ((Callback) getActivity()).onItemSelected(movieId);
        }
    });

    return rootView;
}

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));
    }// w w  w.  j  a va2s .  c om

    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.packpublishing.asynchronousandroid.chapter5.UploadArtworkActivity.java

void initAlbumList() {
    GridView grid = (GridView) findViewById(R.id.album_grid);
    mAdapter = new AlbumCursorAdapter(getApplicationContext(), getSupportLoaderManager());
    grid.setAdapter(mAdapter);

    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w  w  w  . j a  v a  2 s. c o m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) mAdapter.getItem(position);
            int albumId = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Albums._ID));
            Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
            Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);
            Intent intent = new Intent(UploadArtworkActivity.this, UploadArtworkIntentService.class);
            intent.setData(albumArtUri);
            startService(intent);
        }
    });
    getSupportLoaderManager().initLoader(ALBUM_LIST_LOADER, null, UploadArtworkActivity.this);
}

From source file:eu.pellerito.movies.fragment.BaseFragment.java

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

    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_base, container, false);

    mUIAdapter = new UIAdapter(getActivity());

    GridView gridView = (GridView) rootView.findViewById(R.id.my_movie_grid);
    gridView.setAdapter(mUIAdapter);

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*  w  w  w. java 2 s. co m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Parcelable movie = mUIAdapter.getItem(i);

            Intent detailActivity = new Intent(getActivity(), DetailActivity.class).putExtra("UIModel", movie);
            startActivity(detailActivity);

        }
    });

    return rootView;
}

From source file:com.example.android.popularmovies.app.MoviesFragment.java

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

    movieAdapter = new MovieAdapter(getActivity(), movieArray);

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

    GridView gridView = (GridView) rootView.findViewById(R.id.gridview_movie);
    gridView.setAdapter(movieAdapter);

    // gridView.setColumnWidth(Integer.parseInt(getString(R.string.tmdb_image_size_342)));

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from   w  w  w.j a v  a  2  s  .  c om
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Movie movie = movieAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailsActivity.class);
            intent.putExtra("movie", movie);
            startActivity(intent);
        }
    });

    return rootView;
}

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);/*from  w ww . j a  v  a  2  s . c o  m*/
    gridView.setAdapter(imageAdapter);
    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) {

        }
    });
}