This is my adapter for RecyclerView
. How can I get the value of deckName
in another activity?
public class ViewHolder extends RecyclerView.ViewHolder {
public RelativeLayout deckLayout;
public LinearLayout countsLayout;
public ImageButton deckExpander;
public ImageButton indentView;
public TextView deckName;
public TextView deckNew, deckLearn, deckRev;
public ViewHolder(View v) {
super(v);
deckLayout = (RelativeLayout) v.findViewById(R.id.DeckPickerHoriz);
countsLayout = (LinearLayout) v.findViewById(R.id.counts_layout);
deckExpander = (ImageButton) v.findViewById(R.id.deckpicker_expander);
indentView = (ImageButton) v.findViewById(R.id.deckpicker_indent);
deckName = (TextView) v.findViewById(R.id.deckpicker_name);
deckNew = (TextView) v.findViewById(R.id.deckpicker_new);
deckLearn = (TextView) v.findViewById(R.id.deckpicker_lrn);
deckRev = (TextView) v.findViewById(R.id.deckpicker_rev);
}
}
I want get this value and compare it with a string here:
final int itemCount = mDeckListAdapter.getItemCount();
DeckAdapter a = new DeckAdapter(getLayoutInflater(), getApplicationContext());
for(int i=0;i<itemCount;i++){
// final CharSequence text = DeckAdapter.ViewHolder.deckName.getText();
if (text.equals(di)){
mRecyclerView.findViewHolderForAdapterPosition(i).itemView.performClick();
}
}
but this code doesn't really work.
Try this
String title = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)).getText().toString();
I used like
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
String title = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)).getText().toString();
Toast.makeText(getApplicationContext(), title, Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClick(View view, int position) { }
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With