J
J
JohnDaniels2016-03-20 23:58:15
Android
JohnDaniels, 2016-03-20 23:58:15

How to get all TextView on screen?

ArrayAdapter forms a ListView, each of whose elements contains two TextView :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:id="@+id/card"
    android:layout_height="match_parent"
    android:background="@drawable/border"
    android:gravity="center_vertical"
    android:paddingTop="50dp">
    <TextView
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="50dp" />
    <TextView
        android:id="@+id/content2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginLeft="50dp" />
</LinearLayout>

public class CardsDataAdapter extends ArrayAdapter<Card> {
 @Override
        public View getView(int position, final View contentView, ViewGroup parent){
            Card card = getItem(position);

            TextView v1 = (TextView) contentView.findViewById(R.id.content);
            v1.setText(card.word);

            TextView v2 = (TextView) contentView.findViewById(R.id.content2);
            v2.setText(card.translate);

            return contentView;
        }
}

next i need to get ALL TextView android:id="@+id/content2".
findViewById returns one element (and random for some reason), findViewWithTag returns
the same.
tried to dynamically assign tags in getView
TextView v2 = (TextView) contentView.findViewById(R.id.content2);
            v2.setText(card.translate);
            v2.setTag(String.valueOf(position));

//****************************//

findViewWithTag(String.valueOf(1)) // тут все рушится

respectively, questions - how to receive an array of elements on any sign?
How correct is it to create a bunch of elements with the same id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-21
@JohnDaniels

You apparently misunderstand how to work with ListView. You do not, under any circumstances, need an array of these TextViews. Tell me what you want to do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question