如何在另一个活动onClick中显示Cardview中的图像和文本? [英] How to display image and text from Cardview in another activity onClick?

查看:115
本文介绍了如何在另一个活动onClick中显示Cardview中的图像和文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自exoguru的示例应用程序,其中包含cardview,每张卡都包含一张图像和相应的文本.现在,如何在单击该特定卡时在另一个活动中显示该图像和文本?

I have a sample app from exoguru which contains cardview each card consists of an image and corresponding text .Now how to display that image and text in another activity on clicking that particular card?

这是屏幕截图

这是ViewHolder,其中包含卡片视图的onclick

Here is the ViewHolder which contains the onclick for the cardview

 class ViewHolder extends RecyclerView.ViewHolder{

        public ImageView imgThumbnail;
        public TextView tvNature;
        public TextView tvDesNature;

        public ViewHolder(View itemView) {
            super(itemView);
            imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail);
            tvNature = (TextView)itemView.findViewById(R.id.tv_nature);
            tvDesNature = (TextView)itemView.findViewById(R.id.tv_des_nature);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

               v.getContext().startActivity(new Intent(v.getContext(),FullInfo.class));

                }
            });
        }
    }

这是应在其中显示图像和文本的活动布局

This is the layout of the activity in which the image and text should be displayed

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="exoguru.lists.com.naturepics.FullInfo"
style="@style/Base.TextAppearance.AppCompat.Headline">

<ImageView
    android:id="@+id/iv_card"
    android:layout_width="match_parent"
    android:layout_height="140dp" />
<TextView
    android:id="@+id/tv_card_title"
    android:layout_below="@+id/iv_card"

    android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="@dimen/abc_text_size_headline_material" />
<TextView
    android:id="@+id/tv_card"
    android:layout_below="@+id/tv_card_title"
    android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

这些是cardview中的项目

These are the items from cardview

imgThumbnail = (ImageView)itemView.findViewById(R.id.img_thumbnail);   //The image
tvNature = (TextView)itemView.findViewById(R.id.tv_nature);    //The Title
tvDesNature = (TextView)itemView.findViewById(R.id.tv_des_nature);    //The Text

推荐答案

您应在Intent上传递图片url/id/...

You should pass the image url/id/.. on the Intent.

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("imageinfo", imageUrl);
startActivity(intent)

关于目标活动

Bundle bundle = getIntent().getExtras();
String url = bundle.getString("imageinfo"); 

这篇关于如何在另一个活动onClick中显示Cardview中的图像和文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆