【问题标题】:How to set preloaded video pic in cardview and onclicklistener to it?如何在cardview和onclicklistener中设置预加载的视频图片?
【发布时间】:2017-07-01 15:49:40
【问题描述】:

我已成功在 webview 中加载了视频,并且它也在播放,但我想将该链接传递给其他 Activity,它将使用 androidYouTubePlayer 播放视频,并且我想像下面那样显示该 webview。

问题:

  1. 如何显示该视频,如下所示
  2. 如何设置 OnclickListner 以将链接传递给其他活动。

<android.support.v7.widget.CardView
                android:id="@+id/cardViewDemo1"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_margin="5dp"
                android:background="#00ff00"
                android:elevation="3dp"
                app:cardCornerRadius="5dp">

                <WebView
                    android:id="@+id/webView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp" />
            </android.support.v7.widget.CardView>

【问题讨论】:

  • 如何使 cardView 出现如上?
  • 可以是预加载的图像尝试使用它的API加载图像

标签: android webview android-cardview android-youtube-api


【解决方案1】:

将您的链接发送到新活动。

CardView cardView = (CardView) findViewById(R.id.cardViewDemo1);

    cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String linkVideo = "Here, you set this string with link your video ";

            Bundle bundle = new Bundle();
            //HERE, YOU SET YOUR LINK VIDEO, INSIDE KEY "myKeyForReciveLinkVideo";
            bundle.putString("myKeyForReciveLinkVideo",linkVideo);

            //START YOUR ACTIVITY
            Intent i = new Intent(YourActivity,YourActivityGo.class);
           //Send your bundle containing the string with the url link to the new activity.
            startActivity(i,bundle);

        }
    });

在活动中恢复传递给活动的数据。

    //Retrieve the arguments passed to new activity.

    Bundle bundle = new Bundle(getArguments());

    //Use the key you previously defined in the bundle to retrieve the url link string.

    String urlLink = bundle.getString("myKeyForReciveLinkVideo");

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多