golbahar golbahar - 4 years ago 115
Java Question

how can i get the value of text view in recyclerview item?

This is my adapter for

. How can I get the value of
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) {
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)){

but this code doesn't really work.

Answer Source

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() {
        public void onClick(View view, int position) {
          //  String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
            String title1 = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)).getText().toString();
            Toast.makeText(getApplicationContext(), title1, Toast.LENGTH_SHORT).show();

        public void onLongClick(View view, int position) { }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download