【问题标题】:How to display image and text from Cardview in another activity onClick?如何在另一个活动 onClick 中显示来自 Cardview 的图像和文本?
【发布时间】:2015-04-30 10:14:56
【问题描述】:

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

这里是截图

这是包含卡片视图的 onclick 的 ViewHolder

 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));

                }
            });
        }
    }

这是应显示图像和文本的 Activity 布局

<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中的项目

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

【问题讨论】:

  • 显然你必须将 url 传递给资源的图像/图像/id 到另一个活动
  • @Selvin 是的,但是如何?
  • 为什么我的问题被否决了?小心解释。我提出了一个真正的疑问,处理卡片视图布局的点击问题并不多

标签: android onclicklistener android-cardview android-viewholder android-recyclerview


【解决方案1】:

您应该在 Intent 上传递图像 url/id/..。

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

在目的地活动上

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    相关资源
    最近更新 更多