java - 我如何在卡片视图中按 ID 显示从 listview 到下一个意图活动的回收视图数据这是我的代码,请检查并显示结果
问题描述
如何ListView
在卡片视图中按 ID 显示从到下一个意图活动的回收视图数据这是我的代码,请检查并显示结果
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.example.tanuj.recycleview.Product;
import com.example.tanuj.recycleview.R;
import java.util.List;
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ProductViewHolder> {
private TextView textViewTitle,textViewShortDesc,textViewRating,textViewPrice;
private Context mCtx;
private List<Product> productList;
public ProductAdapter(Context mCtx, List<Product> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.product_list, null);
return new ProductViewHolder(view);
}
@Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
Product product = productList.get(position);
Glide.with(mCtx)
.asBitmap()
.load(product.getImage())
.into(holder.imageView);
holder.textViewTitle.setText(product.getTitle());
holder.textViewShortDesc.setText(product.getShortdesc());
holder.textViewRating.setText(String.valueOf(product.getRating()));
holder.textViewPrice.setText(String.valueOf(product.getPrice()));
holder.textViewTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = "{}";
Intent intent = new Intent(mCtx,GalleryActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mCtx.startActivity(intent);
}
});
//Set on click on description
holder.textViewShortDesc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mCtx,"You are click On Description : " +textViewShortDesc,Toast.LENGTH_SHORT).show();
}
});
//Set on click on price
holder.textViewPrice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mCtx,"You are click On Price",Toast.LENGTH_SHORT).show();
}
});
holder.textViewRating.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(mCtx,"You are click on rating",Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return productList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder {
TextView textViewTitle, textViewShortDesc, textViewRating, textViewPrice;
ImageView imageView;
public ProductViewHolder(View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.textViewTitle);
textViewShortDesc = itemView.findViewById(R.id.textViewShortDesc);
textViewRating = itemView.findViewById(R.id.textViewRating);
textViewPrice = itemView.findViewById(R.id.textViewPrice);
imageView = itemView.findViewById(R.id.imageView);
}
}
}
解决方案
- 请让您的产品类(或模型类)实现Parcelable。Android Studio 将为您提供 parcelable 的实现。
- 现在您可以发送任何您的产品对象,如示例
推荐阅读
- c# - Auth0 LoginResult 无法加载 Newtonsoft.Json 10.0.0.0
- python - BeautifulSoup 抓取格式
- javascript - mocha-webpack 找不到测试
- python - Pygame,玩家在房间内与不同墙壁发生碰撞
- javascript - 用公式 javascript 计算
- elixir - 使用 ExUnit 检查状态代码失败,但实际 REST 测试成功
- c# - 在通用方法中返回接口继承的类
- reactjs - 框架或库的生命周期是什么?
- c# - Gremlin,如何获取帖子和所有评论以及评论上的嵌套评论有点像 reddit。在c#中
- c# - C# 字段初始值设定项错误