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.project.eden.EdenMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mainContext = this;

    setProgressBarIndeterminateVisibility(true);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {
        // callback when session changes state
        @Override//ww  w . jav a  2  s .co m
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

                // make request to the /me API
                Request.executeMyFriendsRequestAsync(session, new Request.GraphUserListCallback() {

                    // callback after Graph API response with user object 
                    public void onCompleted(List<GraphUser> users, Response response) {
                        if (users != null && !users.isEmpty()) {
                            LinkedList<String> friendlist = new LinkedList<String>();
                            for (GraphUser user : users) {
                                String u = "https://graph.facebook.com/" + user.getId() + "/picture?type=large";
                                friendlist.add(u);
                            }
                            String[] listofurls = friendlist.toArray(new String[friendlist.size()]);

                            // friendlist now is a string list of all of your friend's profile pic url 
                            GridView gridview = (GridView) findViewById(R.id.gridview);
                            gridview.setAdapter(new ImageAdapter(mainContext, listofurls));

                        }
                    }
                });
            }
        }
    });
}

From source file:com.brayanarias.alarmproject.fragment.CalendarHolidayFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_calendar_holiday, container, false);
    ;/*from ww  w . ja v  a  2 s . c o  m*/
    GridView gridView = (GridView) layout.findViewById(R.id.gvCalendarGrid);
    GridCalendarAdapter gridCalendarAdapter = new GridCalendarAdapter(layout);
    gridView.setAdapter(gridCalendarAdapter);
    return layout;
}

From source file:com.packpublishing.asynchronousandroid.chapter4.AlbumListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.album_list_layout);
    GridView grid = (GridView) findViewById(R.id.album_grid);
    mAdapter = new AlbumCursorAdapter(getApplicationContext(), getSupportLoaderManager());
    grid.setAdapter(mAdapter);
    getSupportLoaderManager().initLoader(ALBUM_LIST_LOADER, null, AlbumListActivity.this);
}

From source file:ca.farrelltonsolar.classic.DayLogCalendar.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    theView = inflater.inflate(R.layout.day_log_calendar, container, false);
    Bundle args = getArguments();//from   www  .  ja v a  2s .  c om
    int monthOffset = args != null ? args.getInt(ARG_MONTH) : 0;
    month = DateTime.now().minusMonths(monthOffset).withTimeAtStartOfDay().withDayOfMonth(1);
    adapter = new CalendarAdapter(this.getActivity(), month);
    GridView gridview = (GridView) theView.findViewById(R.id.gridview);
    gridview.setAdapter(adapter);
    gridview.setVelocityScale(5);

    TextView title = (TextView) theView.findViewById(R.id.title);
    title.setText(month.toString("MMMM yyyy"));
    View linearLayout = theView.findViewById(R.id.headerlayout);
    DateTime days = month;

    for (int i = 0; i < 7; i++) {
        int d = ((i + 6) % 7) + 1;
        days = days.withDayOfWeek(d);
        TextView aDay = new TextView(theView.getContext());
        aDay.setText(DateTimeFormat.forPattern("E").print(days));
        aDay.setGravity(Gravity.CENTER);
        aDay.setTextColor(Color.BLACK);
        aDay.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
        ((LinearLayout) linearLayout).addView(aDay);

    }

    return theView;
}

From source file:com.packpublishing.asynchronousandroid.chapter4.AlbumListActivitySimple.java

void initUI() {
    GridView grid = (GridView) findViewById(R.id.album_grid);
    mAdapter = new AlbumCursorAdapter(getApplicationContext());
    grid.setAdapter(mAdapter);
    // Prepare the loader.  Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(ALBUM_LIST_LOADER, null, AlbumListActivitySimple.this);
}

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

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

}

From source file:com.example.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);

    return v;//from   w w w  .j a v  a2 s  . com
}

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);//from ww  w . j a  v  a  2 s .c o m
    gridView.setAdapter(adapter);
    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:br.com.frs.foodrestrictions.FoodIconGrid.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_restriction_grid, container, false);

    GridView gridview = (GridView) v.findViewById(R.id.gridViewRestrictions);

    Context ctx = container.getContext();

    if (ctx != null) {
        gridview.setAdapter(new FoodImageAdapter(ctx, foodIconList.getFoodRestrictionList(true)));

        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                FoodIconItem foodIconItem = foodIconList.getFoodRestrictionList(false).get(position);

                switch (foodIconItem.getRestrictionType()) {
                case FoodIconList.FOOD_RESTRICTION_TYPE_ALLERGIC:
                    Snackbar.make(v,//from  w ww .j a va2  s .c o m
                            getResources().getString(R.string.allergic_to) + " "
                                    + getResources().getString(foodIconItem.getNameId()),
                            Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    break;
                case FoodIconList.FOOD_RESTRICTION_TYPE_DONT_EAT:
                    Snackbar.make(v,
                            getResources().getString(R.string.dont_eat) + " "
                                    + getResources().getString(foodIconItem.getNameId()),
                            Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    break;
                }
            }
        });
    }

    return v;
}

From source file:com.buddi.client.dfu.FeaturesActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_features);

    // ensure that Bluetooth exists
    if (!ensureBLEExists())
        finish();//from   w ww. j  a v a2s. c  o m

    final DrawerLayout drawer = mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // Set the drawer toggle as the DrawerListener
    drawer.setDrawerListener(mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close));

    // setup plug-ins in the drawer
    setupPluginsInDrawer((ViewGroup) drawer.findViewById(R.id.plugin_container));

    // configure the app grid
    final GridView grid = (GridView) findViewById(R.id.grid);
    grid.setAdapter(new AppAdapter(this));
    grid.setEmptyView(findViewById(android.R.id.empty));

    getActionBar().setDisplayHomeAsUpEnabled(true);
}