私はカードのリストを作成しています。私は、クリックされたカードが持っているTextView内のテキストを取得したいと思います。 カード内のTextViewを取得
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
ImageView productImage;
TextView productName;
TextView productPrice;
TextView productBest;
TextView productURL;
ImageView symbol;
private ViewHolder(View v) {
super(v);
productImage = (ImageView) v.findViewById(R.id.productImage);
productName = (TextView) v.findViewById(R.id.productName);
productPrice = (TextView) v.findViewById(R.id.productPrice);
productBest = (TextView) v.findViewById(R.id.productBest);
productURL = (TextView) v.findViewById(R.id.productURL);
symbol = (ImageView) v.findViewById(R.id.symbol);
v.setOnClickListener(this);
v.setOnLongClickListener(this);
}
@Override
public void onClick(View view) {
TextView urlView = (TextView) view.findViewById(R.id.product_url);
String url = urlView.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
view.getContext().startActivity(intent);
}
@Override
public boolean onLongClick(View view) {
Toast.makeText(view.getContext(), "Long Click",Toast.LENGTH_SHORT).show();
return false;
}
}
しかしのonClick()で
は、urlViewがnullになっている:私のアダプタで私はこれを持っています。私はカードからのものではなく要素からのものであると考えています。私はどうしたらいいですか?
は、ザ・あなたはfindViewByIdを実行するビューパラメータを使用していることである