Grid View with Videos


Last Updated:

  1. kivy

    kivy Member This Topic's Starter

    Joined:
    Jul 13, 2010
    Messages:
    17
    Likes Received:
    0
    Hi there,

    I got a question because I am at the moment stuck. I put some videos on my emulator SD card and would like to access them via the GridView and when you click on a video, a menu should open. How could I do that? Would be great if someone could help me out here...

    Thanks.

    ---------
    What I mean is: based on this code from the Grid View Tut, what would I need to change to display videos from the SD card:

    Code (Text):
    1. public class EditGalleryView extends Activity {
    2.     public void onCreate(Bundle savedInstanceState) {
    3.         super.onCreate(savedInstanceState);
    4.         setContentView(R.layout.videogrid);
    5.        
    6.         GridView vGrid=(GridView) findViewById(R.id.vgrid);
    7.         vGrid.setAdapter(new VideoAdapter(this));
    8.     }
    9.    
    10.     public class VideoAdapter extends BaseAdapter {
    11.         private Context mContext;
    12.        
    13.         public VideoAdapter(Context c) {
    14.             mContext = c;
    15.         }
    16.  
    17.         public int getCount() {
    18.             return mThumbIds.length;
    19.         }
    20.  
    21.         public Object getItem(int position) {
    22.             return null;
    23.         }
    24.  
    25.         public long getItemId(int position) {
    26.             return 0;
    27.         }
    28.  
    29.         // create a new ImageView for each item referenced by the Adapter
    30.         public View getView(int position, View convertView, ViewGroup parent) {
    31.             ImageView imageView;
    32.             if (convertView == null) {  // if it's not recycled, initialize some attributes
    33.                 imageView = new ImageView(mContext);
    34.                 imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
    35.                 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    36.                 imageView.setPadding(8, 8, 8, 8);
    37.             } else {
    38.                 imageView = (ImageView) convertView;
    39.             }
    40.  
    41.             imageView.setImageResource(mThumbIds[position]);
    42.             return imageView;
    43.         }
    44.  
    45.         // references to our images
    46.         private Integer[] mThumbIds = {
    47.                 R.drawable.sample_2, R.drawable.sample_3,
    48.                 R.drawable.sample_4, R.drawable.sample_2,
    49.                 R.drawable.sample_6, R.drawable.sample_3,
    50.                 R.drawable.sample_4, R.drawable.sample_1,
    51.                
    52.         };
    53.        
    54.     }
    55.    
    56.  
    57. }
     

    Advertisement
  2. jungajuice

    jungajuice Active Member

    Joined:
    Mar 30, 2010
    Messages:
    31
    Likes Received:
    1
    you can pass VideoView instead of ImageView back through getView(). You will have to set up each VideoView within the method to find and associate the video with it from your sd instead of pulling a drawable resource.
     

Share This Page

Loading...