List of usage examples for android.widget GridView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:hoahong.facebook.messenger.ui.EmojiView.java
private void init() { setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < Emoji.data.length; i++) { GridView gridView = new GridView(getContext()); if (Utils.isTablet()) { gridView.setColumnWidth(Utils.dp(60)); } else {/*from w w w. j av a 2 s . c o m*/ gridView.setColumnWidth(Utils.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]); gridView.setAdapter(localEmojiGridAdapter); adapters.add(localEmojiGridAdapter); } setBackgroundDrawable( new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 })); pager = new ViewPager(getContext()); pager.setAdapter(new EmojiPagesAdapter()); PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext()); tabs.setViewPager(pager); tabs.setShouldExpand(true); tabs.setIndicatorColor(0xff33b5e5); tabs.setIndicatorHeight(Utils.dpf(2.0f)); tabs.setUnderlineHeight(Utils.dpf(2.0f)); tabs.setUnderlineColor(0x66000000); tabs.setTabBackground(0); LinearLayout localLinearLayout = new LinearLayout(getContext()); localLinearLayout.setOrientation(LinearLayout.HORIZONTAL); localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); ImageView localImageView = new ImageView(getContext()); localImageView.setImageResource(R.drawable.ic_emoji_backspace); localImageView.setScaleType(ImageView.ScaleType.CENTER); localImageView.setBackgroundResource(R.drawable.bg_emoji_bs); localImageView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (EmojiView.this.listener != null) { EmojiView.this.listener.onBackspace(); } } }); localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(Utils.dp(61), LayoutParams.MATCH_PARENT)); recentsWrap = new FrameLayout(getContext()); recentsWrap.addView(views.get(0)); TextView localTextView = new TextView(getContext()); localTextView.setText("No recent"); localTextView.setTextSize(18.0f); localTextView.setTextColor(-7829368); localTextView.setGravity(17); recentsWrap.addView(localTextView); views.get(0).setEmptyView(localTextView); addView(localLinearLayout, new LinearLayout.LayoutParams(-1, Utils.dpf(48.0f))); addView(pager); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }
From source file:com.example.lowviscam.GalleryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); isLight = getIntent().getExtras().getBoolean("isLight"); if (isLight == false) { this.setTheme(R.style.AppBaseThemeDark); } else {/*from w ww .ja v a 2 s. c o m*/ this.setTheme(R.style.AppBaseTheme); } setContentView(R.layout.activity_gallery); // Retrieve APHont font and apply it mFace = Typeface.createFromAsset(getAssets(), "fonts/APHont-Regular_q15c.otf"); SpannableString s = new SpannableString("Image Gallery"); s.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Update the action bar title with the TypefaceSpan instance ActionBar actionBar = getActionBar(); actionBar.setTitle(s); actionBar.setDisplayHomeAsUpEnabled(true); // Fetch the {@link LayoutInflater} service so that new views can be created LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Find the {@link GridView} that was already defined in the XML layout GridView gridView = (GridView) findViewById(R.id.grid); // Initialize the adapter with all the coupons. Set the adapter on the {@link GridView}. try { gridView.setAdapter(new CouponAdapter(inflater, createAllCoupons())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Set a click listener for each picture in the grid gridView.setOnItemClickListener(this); gridView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeTop() { //Toast.makeText(GalleryActivity.this, "top", Toast.LENGTH_SHORT).show(); } public void onSwipeRight() { //Toast.makeText(GalleryActivity.this, "right", Toast.LENGTH_SHORT).show(); } public void onSwipeLeft() { //Toast.makeText(GalleryActivity.this, "left", Toast.LENGTH_SHORT).show(); } public void onSwipeBottom() { //Toast.makeText(GalleryActivity.this, "bottom", Toast.LENGTH_SHORT).show(); } }); gridView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Find coupon that was clicked based off of position in adapter Coupon coupon = (Coupon) parent.getItemAtPosition(position); //Get absolutepath of image for adding. File list[] = mediaStorageDir.listFiles(); File tmpFile = list[list.length - position - 1]; String photoUri = coupon.mImageUri.toString(); try { photoUri = MediaStore.Images.Media.insertImage(getContentResolver(), tmpFile.getAbsolutePath(), null, null); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Create share intent Intent shareIntent = ShareCompat.IntentBuilder.from(GalleryActivity.this).setText(coupon.mTitle) .setType("image/jpeg").setStream(Uri.parse(photoUri)) .setChooserTitle(getString(R.string.share_using)).createChooserIntent(); startActivity(shareIntent); return true; } }); }
From source file:me.cpwc.nibblegram.ui.Components.EmojiView.java
private void init() { setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < Emoji.data.length; i++) { GridView gridView = new GridView(getContext()); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else {//w ww .ja va2 s .co m gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]); gridView.setAdapter(localEmojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999); adapters.add(localEmojiGridAdapter); } setBackgroundColor(0xff222222); pager = new ViewPager(getContext()); pager.setAdapter(new EmojiPagesAdapter()); PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext()); tabs.setViewPager(pager); tabs.setShouldExpand(true); tabs.setIndicatorColor(0xff33b5e5); tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f)); tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f)); tabs.setUnderlineColor(0x66000000); tabs.setTabBackground(0); LinearLayout localLinearLayout = new LinearLayout(getContext()); localLinearLayout.setOrientation(LinearLayout.HORIZONTAL); localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); ImageView localImageView = new ImageView(getContext()); localImageView.setImageResource(R.drawable.ic_emoji_backspace); localImageView.setScaleType(ImageView.ScaleType.CENTER); localImageView.setBackgroundResource(R.drawable.bg_emoji_bs); localImageView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (EmojiView.this.listener != null) { EmojiView.this.listener.onBackspace(); } } }); localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT)); recentsWrap = new FrameLayout(getContext()); recentsWrap.addView(views.get(0)); TextView localTextView = new TextView(getContext()); localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); localTextView.setTextSize(18.0f); localTextView.setTextColor(-7829368); localTextView.setGravity(17); recentsWrap.addView(localTextView); views.get(0).setEmptyView(localTextView); addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f))); addView(pager); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }
From source file:org.bwgz.quotation.fragment.AuthorFragment.java
private void updateQuotations(Cursor cursor) { Log.d(TAG, String.format("updateQuotations - cursor: %s (%d)", cursor, cursor.getCount())); if (cursor.getCount() != 0) { GridView gridView = viewHolder.quotation_grid; if (gridView.getAdapter() instanceof QuotationPicksCursorAdapter) { QuotationPicksCursorAdapter adapter = (QuotationPicksCursorAdapter) gridView.getAdapter(); adapter.swapCursor(cursor);//from w w w . j a v a 2s.c o m } else { QuotationPicksCursorAdapter adapter = new QuotationPicksCursorAdapter(getView().getContext(), cursor, R.layout.author_quotation_pick_view, getImageLoader()); gridView.setAdapter(adapter); } } }
From source file:org.telegram.ui.Views.EmojiView.java
private void init() { setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < Emoji.data.length; i++) { GridView gridView = new GridView(getContext()); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else {/*from w ww . j a v a2 s. c om*/ gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]); gridView.setAdapter(localEmojiGridAdapter); adapters.add(localEmojiGridAdapter); } setBackgroundDrawable( new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 })); pager = new ViewPager(getContext()); pager.setAdapter(new EmojiPagesAdapter()); PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext()); tabs.setViewPager(pager); tabs.setShouldExpand(true); tabs.setIndicatorColor(0xff33b5e5); tabs.setIndicatorHeight(AndroidUtilities.dpf(2.0f)); tabs.setUnderlineHeight(AndroidUtilities.dpf(2.0f)); tabs.setUnderlineColor(0x66000000); tabs.setTabBackground(0); LinearLayout localLinearLayout = new LinearLayout(getContext()); localLinearLayout.setOrientation(LinearLayout.HORIZONTAL); localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); ImageView localImageView = new ImageView(getContext()); localImageView.setImageResource(R.drawable.ic_emoji_backspace); localImageView.setScaleType(ImageView.ScaleType.CENTER); localImageView.setBackgroundResource(R.drawable.bg_emoji_bs); localImageView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (EmojiView.this.listener != null) { EmojiView.this.listener.onBackspace(); } } }); localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT)); recentsWrap = new FrameLayout(getContext()); recentsWrap.addView(views.get(0)); TextView localTextView = new TextView(getContext()); localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); localTextView.setTextSize(18.0f); localTextView.setTextColor(-7829368); localTextView.setGravity(17); recentsWrap.addView(localTextView); views.get(0).setEmptyView(localTextView); addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dpf(48.0f))); addView(pager); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }
From source file:com.negaheno.ui.Components.EmojiView.java
private void init() { setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < Emoji.data.length; i++) { GridView gridView = new GridView(getContext()); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else {//from ww w .ja v a2 s . c o m gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]); gridView.setAdapter(localEmojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999); adapters.add(localEmojiGridAdapter); } setBackgroundColor(0xff222222); pager = new ViewPager(getContext()); pager.setAdapter(new EmojiPagesAdapter()); PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext()); tabs.setViewPager(pager); tabs.setShouldExpand(true); tabs.setIndicatorColor(0xff33b5e5); tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f)); tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f)); tabs.setUnderlineColor(0x66000000); tabs.setTabBackground(0); LinearLayout localLinearLayout = new LinearLayout(getContext()); localLinearLayout.setOrientation(LinearLayout.HORIZONTAL); localLinearLayout.addView(tabs, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f)); ImageView localImageView = new ImageView(getContext()); localImageView.setImageResource(R.drawable.ic_emoji_backspace); localImageView.setScaleType(ImageView.ScaleType.CENTER); localImageView.setBackgroundResource(R.drawable.bg_emoji_bs); localImageView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (EmojiView.this.listener != null) { EmojiView.this.listener.onBackspace(); } } }); localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT)); recentsWrap = new FrameLayout(getContext()); recentsWrap.addView(views.get(0)); TextView localTextView = new TextView(getContext()); localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); localTextView.setTextSize(18.0f); localTextView.setTextColor(-7829368); localTextView.setGravity(17); recentsWrap.addView(localTextView); views.get(0).setEmptyView(localTextView); addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f))); addView(pager); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } updateColors(tabs); }
From source file:ch.ethz.coss.nervousnet.hub.ui.ShowcaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_showcase); GridView gridview = (GridView) findViewById(R.id.space_grid); ArrayList<HashMap<String, String>> formList = new ArrayList<HashMap<String, String>>(); try {//from www. j a va 2 s. c o m String spaceJson = parseJSONFile("res/raw/space.json", getApplicationContext()); JSONObject formArray = (new JSONObject(spaceJson)).getJSONObject("apps"); String app = formArray.getString("app"); String packageName = formArray.getString("package"); NNLog.d(LOG_TAG, "App - " + app + ", Package - " + packageName); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } gridview.setAdapter(new ImageAdapter(ShowcaseActivity.this, getResources().getStringArray(R.array.main_grid), Constants.icons_main_screen)); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { } }); }
From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); boolean newData = false; if (savedInstanceState == null && urls == null) { urls = new ArrayList<String>(); ids = new ArrayList<String>(); newData = true;/*from w w w. j a v a 2 s . co m*/ } else if (savedInstanceState != null) { urls = savedInstanceState.getStringArrayList("urls"); ids = savedInstanceState.getStringArrayList("ids"); } View view = inflater.inflate(R.layout.image_layout, container, false); errorText = (TextView) view.findViewById(R.id.error); mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) errorText.getLayoutParams(); mlp.setMargins(0, 0, 0, 0); view.setPadding(0, getActivity().getActionBar().getHeight(), 0, 0); noImageView = (TextView) view.findViewById(R.id.no_images); GridView gridview = (GridView) view.findViewById(R.id.grid_layout); ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); SharedPreferences settings = activity.getApiCall().settings; gridview.setColumnWidth(Utils.dpToPx( Integer.parseInt(settings.getString(getString(R.string.icon_size), getString(R.string.onetwenty))), getActivity())); imageAdapter = new ImageAdapter(view.getContext()); gridview.setAdapter(imageAdapter); gridview.setOnItemClickListener(new GridItemClickListener()); if (newData) { getImages(); } gridview.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int i2, int i3) { if (lastInView == -1) lastInView = firstVisibleItem; else if (lastInView > firstVisibleItem) { getActivity().getActionBar().show(); lastInView = firstVisibleItem; } else if (lastInView < firstVisibleItem) { getActivity().getActionBar().hide(); lastInView = firstVisibleItem; } } }); return view; }
From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calendar); // on first run, create dummy data: // TODO : get rid of this when deploying SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); boolean firstRun = p.getBoolean("PREFERENCE_FIRST_RUN", true); if (firstRun) { Log.i("PrEPare", "Initial run... Creating dummy data..."); Utils.setDummyAdherenceData(this); p.edit().putBoolean("PREFERENCE_FIRST_RUN", false).apply(); }/*w w w .j a v a 2 s. co m*/ if (preferences == null) { preferences = DataIO.getInstance(this); preferences.addOnDataChangedListener( () -> CalendarActivity.this.runOnUiThread(CalendarActivity.this::refresh)); } loadData(); Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowCustomEnabled(true); } final View v = View.inflate(this, R.layout.menu_item_today, null); TextView txtDate = (TextView) v.findViewById(R.id.txt_today); txtDate.setText(String.valueOf(today.get(Calendar.DATE))); v.setOnClickListener(view -> { finish(); startActivity(getIntent()); // refresh activity }); getSupportActionBar().setCustomView(v); adapter = new CalendarAdapter(this, month, selectedDate); GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(adapter); handler = new Handler(); handler.post(calendarUpdater); GridView headers = (GridView) findViewById(R.id.gvHeaders); ArrayAdapter<String> headersAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new String[] { "S", "M", "T", "W", "T", "F", "S" }); headers.setAdapter(headersAdapter); TextView title = (TextView) findViewById(R.id.title); title.setText(android.text.format.DateFormat.format("MMMM yyyy", month)); final TextView previous = (TextView) findViewById(R.id.previous); previous.setOnClickListener(v13 -> previousMonth()); TextView next = (TextView) findViewById(R.id.next); next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v1) { CalendarActivity.this.nextMonth(); } }); detailsView = findViewById(R.id.details); gridview.setOnItemClickListener((parent, v12, position, id) -> { TextView date = (TextView) v12.findViewById(R.id.date); if (date != null && !date.getText().equals("")) { if (date.getText().toString().equals(String.valueOf(selectedDate.get(Calendar.DATE)))) { displayDetailsView = !displayDetailsView; } else { displayDetailsView = true; } selectedDate.set(Calendar.MONTH, month.get(Calendar.MONTH)); selectedDate.set(Calendar.YEAR, month.get(Calendar.YEAR)); selectedDate.set(Calendar.DATE, Integer.valueOf(date.getText().toString())); refresh(); } }); motionEventListener.setOnSwipeListener(gridview, direction -> { if (direction == CustomMotionEventListener.OnSwipeListener.Direction.LEFT) { nextMonth(); } else if (direction == CustomMotionEventListener.OnSwipeListener.Direction.RIGHT) { previousMonth(); } }); // motionEventListener.setOnSwipeListener(detailsView, onDetailsSwiped); // motionEventListener.setOnSwipeListener(this, onDetailsSwiped); if (addressMapping == null) { // TODO Intent selectDeviceIntent = new Intent(this, SelectDeviceActivity.class); startActivity(selectDeviceIntent); } new CheckForUpdatesTask(this).execute(true); Intent wearableServiceIntent = new Intent(this, WearableService.class); wearableServiceIntent.setAction(Constants.ACTION.START_SERVICE); startService(wearableServiceIntent); Intent dataServiceIntent = new Intent(this, DataService.class); dataServiceIntent.setAction(Constants.ACTION.START_SERVICE); startService(dataServiceIntent); }
From source file:com.ymt.demo1.plates.exportConsult.ExportConsultMainActivity.java
/** * ?// w ww .j av a2 s . c o m */ protected void initOnDutyExpertView() { GridView amDutyView = (GridView) findViewById(R.id.am_expert_gridView); GridView pmDutyView = (GridView) findViewById(R.id.pm_expert_gridView); amAdapter = new DutyExpertAdapter(this); pmAdapter = new DutyExpertAdapter(this); amAdapter.setExpertList(onDutyAmExperts); pmAdapter.setExpertList(onDutyPmExperts); amDutyView.setAdapter(amAdapter); pmDutyView.setAdapter(pmAdapter); AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { OnDutyExpert expert = (OnDutyExpert) parent.getAdapter().getItem(position); Intent intent1 = new Intent(ExportConsultMainActivity.this, ExpertInfoActivity.class); intent1.putExtra("id", Integer.valueOf(expert.getFkUserId())); startActivity(intent1); } }; amDutyView.setOnItemClickListener(itemClickListener); pmDutyView.setOnItemClickListener(itemClickListener); }