Java Code Examples for android.widget.GridView#setAdapter()
The following examples show how to use
android.widget.GridView#setAdapter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FourQuarterQuizView.java From android-topeka with Apache License 2.0 | 6 votes |
@Override protected View createQuizContentView() { mAnswerView = new GridView(getContext()); mAnswerView.setSelector(R.drawable.selector_button); mAnswerView.setNumColumns(2); mAnswerView.setAdapter(new OptionsQuizAdapter(getQuiz().getOptions(), R.layout.item_answer)); mAnswerView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { allowAnswer(); mAnswered = position; } }); return mAnswerView; }
Example 2
Source File: PhoneActivity.java From Sensor-Data-Logger with Apache License 2.0 | 6 votes |
private void setupUi() { setContentView(R.layout.activity_main); floatingActionButton = (FloatingActionButton) findViewById(R.id.floadtingActionButton); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSensorSelectionDialog(); } }); logTextView = (TextView) findViewById(R.id.logText); gridView = (GridView) findViewById(R.id.gridView); List<VisualizationCardData> visualizationCardData = new ArrayList<>(); cardListAdapter = new VisualizationCardListAdapter(this, R.id.gridView, visualizationCardData); gridView.setAdapter(cardListAdapter); }
Example 3
Source File: EnvelopesFragment.java From budget-envelopes with GNU General Public License v3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup cont, Bundle state) { View retVal = inflater.inflate(R.layout.envelopesactivity, cont, false); mPrefs = PreferenceManager .getDefaultSharedPreferences(getActivity().getBaseContext()); mGrid = (GridView) retVal.findViewById(R.id.grid); getLoaderManager().initLoader(0, null, this); mEnvelopes = new EnvelopesAdapter(getActivity(), null); mDeleteAdapter = new DeleteAdapter(getActivity(), this, mEnvelopes, 0); mGrid.setAdapter(mDeleteAdapter); mGrid.setOnItemClickListener(this); mTotalContainer = retVal.findViewById(R.id.totalamount); mTotal = (TextView) mTotalContainer.findViewById(R.id.value); mTotalLabel = mTotalContainer.findViewById(R.id.name); mScroll = (MonitorScrollView) retVal.findViewById(R.id.scroll); mScroll.setOnScrollListener(this); return retVal; }
Example 4
Source File: MainActivity.java From RatioImageView with The Unlicense | 6 votes |
private void setupGrid(int layoutResId) { ArrayAdapterItem adapter = new ArrayAdapterItem(this, layoutResId, new String[] { "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "property_1.jpg", "property_2.jpg", "property_3.jpg", "property_4.jpg", "land_highres_1.jpg", "land_highres_2.png", "port_highres_1.jpg", "port_highres_2.png"}); GridView grid = (GridView) findViewById(R.id.gridview); grid.setAdapter(adapter); adapter.notifyDataSetChanged(); }
Example 5
Source File: EmojiconRecentsGridView.java From AndroidKeyboard with GNU General Public License v3.0 | 6 votes |
public EmojiconRecentsGridView(Context context, Emojicon[] emojicons, EmojiconRecents recents,EmojiconsPopup emojiconsPopup) { super(context, emojicons, recents, emojiconsPopup); EmojiconRecentsManager recents1 = EmojiconRecentsManager .getInstance(rootView.getContext()); mAdapter = new EmojiAdapter(rootView.getContext(), recents1); mAdapter.setEmojiClickListener(new OnEmojiconClickedListener() { @Override public void onEmojiconClicked(Emojicon emojicon) { if (mEmojiconPopup.onEmojiconClickedListener != null) { mEmojiconPopup.onEmojiconClickedListener.onEmojiconClicked(emojicon); } } }); GridView gridView = (GridView) rootView.findViewById(R.id.Emoji_GridView); gridView.setAdapter(mAdapter); }
Example 6
Source File: GalleryFragment.java From remoteyourcam-usb with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { formatParser = new SimpleDateFormat("yyyyMMdd'T'HHmmss.S"); currentScrollState = OnScrollListener.SCROLL_STATE_IDLE; View view = inflater.inflate(R.layout.gallery_frag, container, false); storageSpinner = (Spinner) view.findViewById(R.id.storage_spinner); storageAdapter = new StorageAdapter(getActivity()); storageSpinner.setAdapter(storageAdapter); emptyView = (TextView) view.findViewById(android.R.id.empty); emptyView.setText(getString(R.string.gallery_loading)); galleryView = (GridView) view.findViewById(android.R.id.list); galleryAdapter = new GalleryAdapter(getActivity(), this); galleryAdapter.setReverseOrder(getSettings().isGalleryOrderReversed()); galleryView.setAdapter(galleryAdapter); galleryView.setOnScrollListener(this); galleryView.setEmptyView(emptyView); galleryView.setOnItemClickListener(this); orderCheckbox = (CheckBox) view.findViewById(R.id.reverve_order_checkbox); orderCheckbox.setChecked(getSettings().isGalleryOrderReversed()); orderCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { onReverseOrderStateChanged(isChecked); } }); enableUi(false); ((SessionActivity) getActivity()).setSessionView(this); return view; }
Example 7
Source File: ComposeTweetActivity.java From catnut with MIT License | 5 votes |
private void injectLayout() { // for panel mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout); mEmotions = (GridView) findViewById(R.id.emotions); mEmotions.setAdapter(new EmotionsAdapter(this)); mEmotions.setOnItemClickListener(this); mSlidingPaneLayout.setPanelSlideListener(new SliderListener()); mSlidingPaneLayout.openPane(); mSlidingPaneLayout.getViewTreeObserver().addOnGlobalLayoutListener(new FirstLayoutListener()); // for tweet mAvatar = (ImageView) findViewById(R.id.avatar); mScreenName = (TextView) findViewById(R.id.screen_name); mText = (EditText) findViewById(R.id.text); mLocationMarker = findViewById(R.id.location_marker); // set data to layout... new AsyncQueryHandler(getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { Picasso.with(ComposeTweetActivity.this) .load(cursor.getString(cursor.getColumnIndex(User.avatar_large))) .placeholder(R.drawable.error) .error(R.drawable.error) .into(mAvatar); mScreenName.setText("@" + cursor.getString(cursor.getColumnIndex(User.screen_name))); } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(User.MULTIPLE, mApp.getAccessToken().uid), new String[]{User.avatar_large, User.screen_name}, null, null, null); // other stuffs... mText.addTextChangedListener(this); }
Example 8
Source File: EmoticonFragment.java From BlackLight with GNU General Public License v3.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.emoticon_fragment, null); mGrid = (GridView) v.findViewById(R.id.emoticon_grid); // adapter mAdapter = new EmoticonAdapter(getActivity()); mGrid.setAdapter(mAdapter); // listener mGrid.setOnItemClickListener(this); return v; }
Example 9
Source File: EmojiconRecentsGridFragment.java From emojicon with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { EmojiconRecentsManager recents = EmojiconRecentsManager .getInstance(view.getContext()); mAdapter = new EmojiconAdapter(view.getContext(), recents, mUseSystemDefault); GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView); gridView.setAdapter(mAdapter); gridView.setOnItemClickListener(this); }
Example 10
Source File: CityManagerActivity.java From CoolWeather with Apache License 2.0 | 5 votes |
private void initView() { mCityManagerEntity = new ArrayList<CityManagerEntity>(); mGrid = (GridView) findViewById(R.id.gridview); mGrid.setNumColumns(3); mGrid.setBackgroundResource(R.drawable.bg_homepager_blur); mGrid.setAdapter(new GridCityMAdapter(this, mCityManagerEntity)); }
Example 11
Source File: ColorsDialog.java From FileManager with Apache License 2.0 | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(true); View view = View.inflate(getActivity(), R.layout.dialog_md_colors, null); GridView gridView = (GridView) view.findViewById(R.id.grid); gridView.setAdapter(new MDColorsAdapter()); gridView.setOnItemClickListener(this); return new MaterialDialog.Builder(getActivity()) .customView(view, false) .positiveText(R.string.cancel) .build(); }
Example 12
Source File: LotteryAPIActivity.java From stynico with MIT License | 5 votes |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lottery); StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary)); etPeriod = forceCast(findViewById(R.id.etPeriod)); tvDateTime = forceCast(findViewById(R.id.tvDateTime)); tvName = forceCast(findViewById(R.id.tvName)); tvSales = forceCast(findViewById(R.id.tvSales)); tvPool = forceCast(findViewById(R.id.tvPool)); tvPeriod = forceCast(findViewById(R.id.tvPeriod)); tvLotteryNumber = forceCast(findViewById(R.id.tvLotteryNumber)); GridView gvLotteryList = forceCast(findViewById(R.id.gvLotteryList)); ListView lvLotteryResult = forceCast(findViewById(R.id.lvLotteryAward)); gvLotteryList.setOnItemClickListener(this); //init data updateLotteryInfo(null, null, null, null, null, null); lotteryTypeList = new ArrayList<HashMap<String, Object>>(); lotteryTypeListAdapter = new SimpleAdapter(this, lotteryTypeList, android.R.layout.simple_list_item_1, new String[]{"name"}, new int[]{android.R.id.text1}); gvLotteryList.setAdapter(lotteryTypeListAdapter); lotteryResultList = new ArrayList<HashMap<String, Object>>(); lotteryResultAdapter = new LotteryResultAdapter(this, lotteryResultList); lvLotteryResult.setAdapter(lotteryResultAdapter); //获取彩种列表 ((Lottery) forceCast(MobAPI.getAPI(Lottery.NAME))).queryLotteryList(LotteryAPIActivity.this); }
Example 13
Source File: LayoutAnimation6.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); loadApps(); setContentView(R.layout.layout_animation_6); GridView grid = (GridView) findViewById(R.id.grid); grid.setAdapter(new AppsAdapter()); }
Example 14
Source File: StickGridItemListFragment.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mGridView = (GridView)view.findViewById(R.id.asset_grid); mGridView.setOnItemClickListener(this); /* * Currently set in the XML layout, but this is how you would do it in * your code. */ // mGridView.setColumnWidth((int) calculatePixelsFromDips(100)); // mGridView.setNumColumns(StickyGridHeadersGridView.AUTO_FIT); mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(getActivity() .getApplicationContext(), getResources().getStringArray(R.array.countries), R.layout.stickygridheader_header, R.layout.stickygridheader_item)); if (savedInstanceState != null) { mFirstVisible = savedInstanceState.getInt(KEY_LIST_POSITION); } mGridView.setSelection(mFirstVisible); // Restore the previously serialized activated item position. if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) { setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); } ((StickyGridHeadersGridView)mGridView).setOnHeaderClickListener(this); ((StickyGridHeadersGridView)mGridView).setOnHeaderLongClickListener(this); setHasOptionsMenu(true); }
Example 15
Source File: ImageRequestFragment.java From android-open-project-demo with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fr_image_request, container,false); gvCar = (GridView) view.findViewById(R.id.gv_car); ImageBaseAdapter adapter = new ImageRequestAdapter(getActivity(),imageUrlArray); gvCar.setAdapter(adapter); return view; }
Example 16
Source File: SmileyPicker.java From iBeebo with GNU General Public License v3.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.smileypicker_gridview, container, false); GridView gridView = (GridView) view.findViewById(R.id.smiley_grid); gridView.setAdapter(new SmileyAdapter(mContext, position)); container.addView(view, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return view; }
Example 17
Source File: FanartSearchFragment.java From Mizuu with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); if (mImageUrls.size() > 0) mProgressBar.setVisibility(View.GONE); // Hack to remove the ProgressBar on orientation change mGridView = (GridView) v.findViewById(R.id.gridView); mAdapter = new ImageAdapter(getActivity()); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Create the download Service Intent downloadService = new Intent(getActivity(), DownloadImageService.class); downloadService.putExtra(DownloadImageService.CONTENT_ID, mTmdbId); downloadService.putExtra(DownloadImageService.IMAGE_URL, mImageUrls.get(arg2)); downloadService.putExtra(DownloadImageService.IMAGE_TYPE, DownloadImageService.IMAGE_TYPE_MOVIE_BACKDROP); getActivity().startService(downloadService); // End the browser Activity getActivity().finish(); } }); mJson = getArguments().getString("json"); loadJson(getArguments().getString("baseUrl")); }
Example 18
Source File: CustomShapeImageViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_shape_image_view_activity); GridView gridView = (GridView) findViewById(R.id.gridview); gridView.setAdapter(new SvgImagesAdapter(this)); }
Example 19
Source File: UiTestUtils.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
public static void setDummyData(Context context, GridView gridView) { gridView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, getDummyData())); }
Example 20
Source File: PaletteFragment.java From color-picker with Apache License 2.0 | 4 votes |
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /* * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.dmfs_colorpickerdialog_palette_grid, container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use * a hard coded value of 8 dip. * * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid unnecessary updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }