Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Android
How to put n intent on a gridview to lauch another activity in android?
md firhan
Greenhorn
Posts: 1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, I doing a grid view for my android layout but I don't know how to put an intent on the grid view. is there any way where I can put an intent to launch another activity?
PregnancyStages.java package sp.com; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.ViewGroup.LayoutParams; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; public class PregnancyStages extends Activity { private GridView photoGrid; private int mPhotoSize, mPhotoSpacing; private ImageAdapter imageAdapter; // Some items to add to the GRID private static final String[] CONTENT = new String[] { "Pregnancy Stages", "Complications", "Diet And Fitness", "Myths And Facts", "FAQ's", "Helplines" }; private static final int[] ICONS = new int[] { R.drawable.baby1, R.drawable.baby2, R.drawable.baby3, R.drawable.baby4, R.drawable.baby5, R.drawable.baby6 }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // get the photo size and spacing mPhotoSize = getResources().getDimensionPixelSize(R.dimen.photo_size); mPhotoSpacing = getResources().getDimensionPixelSize(R.dimen.photo_spacing); // initialize image adapter imageAdapter = new ImageAdapter(); photoGrid = (GridView) findViewById(R.id.albumGrid); // set image adapter to the GridView photoGrid.setAdapter(imageAdapter); // get the view tree observer of the grid and set the height and numcols dynamically photoGrid.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (imageAdapter.getNumColumns() == 0) { final int numColumns = (int) Math.floor(photoGrid.getWidth() / (mPhotoSize + mPhotoSpacing)); if (numColumns > 0) { final int columnWidth = (photoGrid.getWidth() / numColumns) - mPhotoSpacing; imageAdapter.setNumColumns(numColumns); imageAdapter.setItemHeight(columnWidth); } } } }); } // ///////// ImageAdapter class ///////////////// public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater; private int mItemHeight = 0; private int mNumColumns = 0; private RelativeLayout.LayoutParams mImageViewLayoutParams; public ImageAdapter() { mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } public int getCount() { return CONTENT.length; } // set numcols public void setNumColumns(int numColumns) { mNumColumns = numColumns; } public int getNumColumns() { return mNumColumns; } // set photo item height public void setItemHeight(int height) { if (height == mItemHeight) { return; } mItemHeight = height; mImageViewLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, mItemHeight); notifyDataSetChanged(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(final int position, View view, ViewGroup parent) { if (view == null) view = mInflater.inflate(R.layout.photo_item, null); ImageView cover = (ImageView) view.findViewById(R.id.cover); TextView title = (TextView) view.findViewById(R.id.title); cover.setLayoutParams(mImageViewLayoutParams); // Check the height matches our calculated column width if (cover.getLayoutParams().height != mItemHeight) { cover.setLayoutParams(mImageViewLayoutParams); } cover.setImageResource(ICONS[position % ICONS.length]); title.setText(CONTENT[position % CONTENT.length]); return view; } } } PregnancytagesGrid1 package sp.com; import android.app.Activity; import android.os.Bundle; public class PregnancyStagesGrid1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pregnancystagesgrid1); } } PregnancyStagesGrid2 package sp.com; import android.app.Activity; import android.os.Bundle; public class PregnancyStagesGrid2 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pregnancystagesgrid2); } }
Steve Luke
Bartender
Posts: 4179
22
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you be more specific about what you want to do? 'Putting an intent on a gridview' doesn't really make sense.
Steve
it's a teeny, tiny, wafer thin ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to display Images stored on sdcard?
How to add new country and flag in the list view
How to create a toast via button click
how to use tamil fonts in android mobile
How to add text to gridview
More...