1
即时退出编程和Android的新功能。 我想让我的VideoView在它自己的类中,并在我的BaseAdapter中的getView()方法中调用它,所以我没有在我的Switch案例中的所有内容。在BaseAdapter中为VideoView设置VideoView
这是我的getView()方法。我知道MOKVideoView videoView = new MOKVideoView(context);部分是不正确的,但我无法弄清楚如何调用它。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int resource = 0;
switch (getItemViewType(position)) {
case 0:
resource = R.layout.headline_item;
break;
case 1:
resource = R.layout.videoplayer_item;
break;
}
View rowView = convertView;
if (rowView == null) {
rowView = mLayoutInflater.inflate(resource, null);
}
switch (resource){
case R.layout.headline_item:
TextView headline = (TextView) rowView.findViewById(R.id.headline);
headline.setText("Hey Hey");
break;
case R.layout.videoplayer_item:
MOKVideoView videoView = new MOKVideoView(context);
return videoView.getmVideoView();
}
return rowView;
}
,在这里我MOKVideoView类
public MOKVideoView(Context context) {
super(context);
initVideoView();
}
public MOKVideoView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
initVideoView();
}
public MOKVideoView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initVideoView();
}
public View initVideoView() {
View view = mLayoutInflater.inflate(R.layout.videoplayer_item, null, false);
mVideoView = (VideoView) view.findViewById(R.id.video);
countDownText = (TextView) view.findViewById(R.id.timer);
countDownTimer = new MyCountDownTimer(startTime, interval);
try {
//set the uri of the video to be played
mVideoView.setVideoURI(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.test_vid));
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
抱歉不好解释!
谢谢,我理解了它看到您的帖子:)之后。不知道这是可能的。 – 2014-09-23 12:58:34