Android 在ListView的BaseAdapter中设置VideoView

Android 在ListView的BaseAdapter中设置VideoView,android,android-listview,android-adapter,Android,Android Listview,Android Adapter,我刚开始编程和安卓系统。 我想让我的VideoView在它自己的类中,并在BaseAdapter的getView()方法中调用它,所以我的Switch案例中没有所有内容 下面是我的getView()方法。我知道MOKVideoView videoView=新的MOKVideoView(上下文);部分不正确,但我不知道如何称呼它 @Override public View getView(int position, View convertView, ViewGroup parent) {

我刚开始编程和安卓系统。 我想让我的VideoView在它自己的类中,并在BaseAdapter的getView()方法中调用它,所以我的Switch案例中没有所有内容

下面是我的getView()方法。我知道MOKVideoView videoView=新的MOKVideoView(上下文);部分不正确,但我不知道如何称呼它

 @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();
    }

对不起,解释得不好

我不确定你的问题是否正确。您的意思是要为listview的每个元素创建视频视图吗?如果是这样的话,您必须使用视频视图创建一个xml文件,并让您的适配器对其进行扩展

例:


谢谢,我在看到你的帖子后发现了:)。我不知道这是可能的。
listview_item.xml:
<linearLayout
    android:layout_width = "fill_parent"
    android:layout_height = "fill_parent"

    <MOKVideoView     
        android:layout_width = "fill_parent"
        android:layout_height = "fill_parent"
        android:id = "MOKVideo" />

</linearLayout>
MOKVideoView mokvideo = (MOKVideoView) getView.findViewById(R.id.MOKVideo);