0

I have a video activity that videos load from Raw folder.

I want in my grid view when i click a item it send an video link to video activity

what i can add this address to per icon in gridview ?

my videos name like this one.3gp two.3gp three.3gp ....

main.java*

GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), video.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }

    });

imageadapter.java

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(120, 120));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images
public Integer[] mThumbIds = {
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2,
        R.drawable.sample_2, R.drawable.sample_2
};

}

and video.java

add = getIntent().getStringExtra("id");
    VideoView myvid = (VideoView) findViewById(R.id.videoview);

    myvid.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.sigarintro));
    myvid.setMediaController(new MediaController(this));
    myvid.requestFocus();


    myvid.start();
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
pencilvania
  • 276
  • 1
  • 4
  • 18

2 Answers2

1

Not sure what is the problem but if i understand correctly: I have activity that is host of two fragments, if i want to get some variable/value from my activity to my fragment, i just type in fragment:

String currentPath = ((MainActivity)getActivity()).currentPath;

This thread is i think similar maybe... link

Community
  • 1
  • 1
Vasil Valchev
  • 5,701
  • 2
  • 34
  • 39
0
path = "your path";

mVideoView.setVideoPath(path);
myvid.setMediaController(new MediaController(this));
myvid.requestFocus();

myvid.start();
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
Lochana Ragupathy
  • 4,320
  • 2
  • 25
  • 36