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:com.simplifynowsoftware.flickrdemo.FavoritesFragment.java

protected void showPhotos(List<PhotoCommon> photos) {
    if (null == photos) {
        if (FlickrDemoConstants.DEBUG_ENABLE) {
            Log.w("showPhotos", "Failed to show photos, null input");
        }/*from w  w  w.  ja v  a  2 s .co m*/
    } else {
        final GridView gridView = (GridView) getActivity().findViewById(R.id.favoritesFragment)
                .findViewById(R.id.photosetGridView);

        gridView.setAdapter(new PhotoAdapter(getActivity(), photos));

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                PhotoCommon photo = (PhotoCommon) gridView.getItemAtPosition(position);

                final Intent intent = new Intent(getActivity(), PhotoViewer.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(PhotoViewer.INTENT_EXTRA_PHOTO_URL,
                        FlickrImageUrl.getUrl(photo, FlickrImageUrl.USE_FULL_SIZE));
                intent.putExtra(PhotoViewer.INTENT_EXTRA_PHOTO_ID, photo.getId());
                intent.putExtra(PhotoViewer.INTENT_EXTRA_PHOTO_SECRET, photo.getSecret());
                startActivity(intent);

                if (FlickrDemoConstants.DEBUG_ENABLE) {
                    Log.i("showPhotos", "Clicked on photo id " + photo.getId());
                }
            }
        });
    }
}

From source file:com.antonioleiva.materialeverywhere.HomeActivity1.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarIcon(R.drawable.ic_ab_drawer);

    GridView gridView = (GridView) findViewById(R.id.gridView);
    gridView.setAdapter(new GridViewAdapter());
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from ww w .ja v  a2  s  .  c  o m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String url = (String) view.getTag();
            DetailActivity.launch(HomeActivity1.this, view.findViewById(R.id.image), url);

        }
    });

    drawer = (DrawerLayout) findViewById(R.id.drawer);
    drawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    NotificationManager notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notifier.cancel(ACTION_NOTIFICATION_ID);

    //?  ?? 
    Intent intent1 = new Intent(this, HomeActivity1.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(this, ACTION_NOTIFICATION_ID, intent1, 0);

    NotificationCompat.WearableExtender secondWearableExtender = new NotificationCompat.WearableExtender()
            .setContentIcon(R.drawable.ic_launcher).setContentIconGravity(Gravity.CENTER);
    //step4
    Notification secondPage = new NotificationCompat.Builder(this).setContentTitle("Step 4")
            .setContentText("  ? ? ? ?.")
            .extend(secondWearableExtender).build();
    //5 
    NotificationCompat.Action step5 = new NotificationCompat.Action(R.drawable.ic_launcher, "step5",
            viewPendingIntent);
    //step5
    Notification thirdPage = new NotificationCompat.Builder(this).setContentTitle("Step 5")
            .setContentText("    .")
            .extend(new NotificationCompat.WearableExtender().setContentIcon(R.drawable.ic_launcher)
                    .setContentIconGravity(Gravity.CENTER).setContentAction(0))

            .build();
    //step6
    Notification fourthPage = new NotificationCompat.Builder(this).setContentTitle("Step 6")
            .setContentText("   ? .")
            .extend(new NotificationCompat.WearableExtender().setContentIcon(R.drawable.ic_launcher)
                    .setContentIconGravity(Gravity.CENTER))
            .build();

    // ??   ? ?.
    //?,  ? 
    NotificationCompat.WearableExtender wearableOptions = new NotificationCompat.WearableExtender()
            .setContentIcon(R.drawable.ic_launcher).setContentIconGravity(Gravity.CENTER).addAction(step5)
            .addPage(secondPage).addPage(thirdPage).addPage(fourthPage);

    //  ? ? ?

    Notification notification = new NotificationCompat.Builder(this).setContentTitle("?")
            .setContentText("2").setUsesChronometer(true).setSmallIcon(R.drawable.ic_launcher)
            .extend(wearableOptions).setAutoCancel(true).build();
    //? 

    //  ? ? .
    NotificationManagerCompat.from(this).notify(RECIPE_NOTIFICATION_ID, notification);
}

From source file:gov.wa.wsdot.android.wsdot.ui.FlickrActivity.java

private void showImages() {
    try {//from  ww w. jav a2s . c o  m
        GridView gridView = (GridView) findViewById(R.id.gridview);
        gridView.setAdapter(this.adapter);
        gridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Bundle b = new Bundle();
                Intent intent = new Intent(FlickrActivity.this, FlickrDetailsActivity.class);
                b.putString("title", mFlickrItems.get(position).getTitle());
                b.putString("link", mFlickrItems.get(position).getLink());
                b.putString("content", mFlickrItems.get(position).getContent());
                intent.putExtras(b);
                startActivity(intent);
            }
        });

    } catch (Exception e) {
        Log.e("DEBUG_TAG", "Error getting images", e);
    }
}

From source file:blackman.matt.catalog.CatalogActivity.java

/**
 * Called when the catalog gets loaded from the web.
 *
 * @param jsonArray The array of threads from the catalog.
 *//*from   w ww.  j av  a  2  s. c o  m*/
@Override
public void pageLoaded(JSONArray jsonArray) {
    GridView grid = (GridView) findViewById(R.id.grid_gallery);
    mAdapter = new CatalogAdapter(this, mPosts, grid.getMeasuredWidth());
    grid.setOnScrollListener(new EndlessScrollListener(jsonArray));
    grid.setAdapter(mAdapter);
}

From source file:com.hellosky.recyclingimageloader.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.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override/*  w  w  w.  j av  a  2 s  .  c  o m*/
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        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 (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                }
            }
        }
    });

    return v;
}

From source file:com.acceleratedio.pac_n_zoom.PickAnmActivity.java

private void dsply_thumbnails(String tags) {
    // tags is a string that holds a 3 dimension array with a different delimiter
    // for each dimension. The most significant dimension is delimited with '|'.
    // The second dimension is delimited with a comma. The least dimension 
    // significant is '/' for [0][] and ' ' for [1][].
    top_dim = tags.split("\\|");
    fil_nams = top_dim[0].split("\\,");

    if (req_str.equals(""))
        orgnl_tags = top_dim[1]; // Used when saving animation

    GridView gv = (GridView) findViewById(R.id.tnview);
    gv.setAdapter(new ImageAdapter(this));

    gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from  w  w w .  j  a v a  2  s  .co m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (mod_str.equals("animation")) {
                Intent intent = new Intent(PickAnmActivity.this,
                        com.acceleratedio.pac_n_zoom.AnimActivity.class);
                intent.putExtra("position", position);
                startActivity(intent);
            } else {
                Intent intent = new Intent(PickAnmActivity.this, com.acceleratedio.pac_n_zoom.ViewVideos.class);
                intent.putExtra("position", position);
                startActivity(intent);
            }
        }
    });

    searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            boolean handled = false;
            req_str = searchEditText.getText().toString();

            if (actionId == EditorInfo.IME_ACTION_SEND) {

                MakePostRequest get_tags = new MakePostRequest();
                get_tags.execute(req_str);
                handled = true;
            }

            return handled;
        }
    });
}

From source file:biz.easymenu.easymenung.TableListFragment.java

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

    View v = inflater.inflate(R.layout.menupager, container, false);
    ((TextView) v.findViewById(R.id.menuTitle)).setText(R.string.tableList);
    GridView gridview = (GridView) v.findViewById(R.id.gridview);
    adapter = new ItemAdapter(getActivity());
    gridview.setAdapter(adapter);

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            DialogFragment f = new LoginFragment(adapter.itemsList.get(position));
            Fragment prev = fm.findFragmentByTag("loginDialog");
            if (prev != null) {
                ft.remove(prev);/*  w  w  w . j a v  a  2 s  .  co m*/
                ft.commit();
            }
            f.show(ft, "loginDialog");

            /*DEMO
                    
            Locale pLocale = new Locale("it");
            Resources res = getActivity().getBaseContext().getResources();
            DisplayMetrics dm =  getActivity().getBaseContext().getResources().getDisplayMetrics();
            Configuration conf = res.getConfiguration();
            conf.locale = pLocale;
            res.updateConfiguration(conf, dm);
            getActivity().finish();
            startActivity(getActivity().getIntent());
                    
                    
            END DEMO */
        }
    });

    return v;
}

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  .  j  a va  2 s  .  c o  m*/
    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:net.pejici.easydice.fragment.DiceRollerFragment.java

private void setupDiceButtons(View rootView) {
    GridView buttonGrid = (GridView) rootView.findViewById(R.id.dice_buttons_grid);
    DieViewArrayAdapter<Die> adapter = new DieViewArrayAdapter<Die>(this.getActivity(), 0,
            Die.allLargestSizeDice());// w  ww.j ava  2s. c  o m
    buttonGrid.setAdapter(adapter);
    OnItemClickListener cl = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View dieView, int position, long id) {
            Die die = (Die) parent.getAdapter().getItem(position);
            hand.addDie(die);
        }
    };
    buttonGrid.setOnItemClickListener(cl);
}

From source file:com.vector.wemarried.android.utils.bitmapfun.ui.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.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override/*from ww w  . ja  v a 2s .c o  m*/
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        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 (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                }
            }
        }
    });

    return v;
}