E
E
Eugene2017-04-03 21:35:54
Java
Eugene, 2017-04-03 21:35:54

RecyclerView problem?

@Override
    public void onBindViewHolder(final QuizViewHolder quizViewHolder, int i) {
        quizViewHolder.quizName.setText(quizs.get(i).getName());<b></b>
        quizViewHolder.quizCost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, quizViewHolder.quizCost.getText().toString());
            }
        });

    }

How to pass what is in the log in onBindViewHolder to the TextView Which hangs in the layout above the entire RecyclerView design?
TextView textView = (TextView) view.findViewById(R.id.textView); - doesn't work
quizViewHolder.textview.setText("Text from log");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Myvrenik, 2017-04-03
@gim0

How to pass what is in the log in onBindViewHolder to the TextView Which hangs in the layout above the entire RecyclerView design?

You are clearly doing something wrong. The adapter should not know, much less manipulate with the layout in which the RecyclerView is located. To do this, you need to pass information to the Activity/Fragment that contains the RecyclerView. And he (Activity / Fragment), in turn, already exposes the text where you need based on the information received. You can implement it, for example, by creating a special interface of the "listener" type and passing the implementation of the interface from the Activity / Fragment to the adapter, which will call the interface method with the necessary arguments (in your case, just text). See template .
And I do not recommend using getText() to get text from the View, as you do. Views should only display information to the user, not be a container for data used in code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question