Customize the text view of the included layout

I have a layout as follows:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/logo_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/logos_background">
        </ImageView>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:layout_alignBottom="@+id/logo_background"
            >
            <TextView
                android:id="@+id/logoDetails"
                android:text="Test Logo details"
                android:textSize="15sp"
                android:layout_centerHorizontal="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <TextView
                android:id="@+id/stockQuantity"
                android:layout_centerHorizontal="true"
                android:textSize="20sp"
                android:layout_below="@+id/logoDetails"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"    
                android:text="x10"/>

        </RelativeLayout>
    </RelativeLayout>    
</RelativeLayout>

I need to include this layout several times in another layout, which I did as follows:

<HorizontalScrollView
    android:layout_below = "@+id/selectLayout"
    android:id="@+id/pager"
    android:scrollbars="none"
    android:layout_marginLeft="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
        <include layout="@layout/viewpager_item_layout"/>
    </LinearLayout>
</HorizontalScrollView>

This gives the following result: enter image description here

The problem is that I need to access text representations and image representations in each <include>. Thus, the image of the logo will be different, the data of the test logo will be different, and the "x10" will be different for each of them, since I hope to fill them out from the database. Can anyone shed some light on this?

It was my intention to use the view pager for this, but this does not work as it takes up the entire width and height of the screen.

+4
2
<include android:id="@+id/news_title"
         layout="@layout/viewpager_item_layout"/>

, .

:

View includedLayout = findViewById(R.id.news_title);
TextView insideTheIncludedLayout = (TextView )includedLayout.findViewById(R.id.logoDetails);
+5

include, :

   View v = findViewById(R.id.your_layout_id);
   TextView tv = (TextView) v.findViewById(R.id.text_view_id);
+1

All Articles