我有一个视频活动,视频从Raw文件夹加载。
我想在我的网格视图中点击某个项目时,会向视频活动发送视频链接
我可以在gridview中为每个图标添加此地址吗?
我的视频名称如此.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
};
}
和 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();
答案 0 :(得分:1)
不确定是什么问题,但如果我理解正确:我的活动是两个片段的主机,如果我想从我的活动中获取一些变量/值到我的片段,我只需输入片段:
String currentPath = ((MainActivity)getActivity()).currentPath;
这个帖子我觉得可能类似...... link
答案 1 :(得分:0)
path = "your path";
mVideoView.setVideoPath(path);
myvid.setMediaController(new MediaController(this));
myvid.requestFocus();
myvid.start();