Pekus
Pekus

Reputation: 155

Load images from tableLayout android

I have five rows imageView, but this code load only 4 rows? why?

Java code

tl = (TableLayout) findViewById(R.id.tableLayout);
for (int i = 0; i < tl.getChildCount(); i++) {
    View v = tl.getChildAt(i);
    if (v instanceof TableRow) {

        for (int j = 0; j < ((TableRow) v).getChildCount(); j++) {
            View innerView = ((TableRow) v).getChildAt(j);
            if (innerView instanceof ImageView) {
                imageList.add((ImageView) innerView);
                idList.add(innerView.getId());
            }
        }
    }
}

Layout

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="false"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="275dp"
        android:id="@+id/tableLayout">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView3"
                android:layout_column="1"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView2"
                android:layout_column="2"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView"
                android:layout_column="3"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView25"
                android:layout_column="5"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView5"
                android:layout_column="6"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView13"
                android:layout_column="1"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView12"
                android:layout_column="2"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView11"
                android:layout_column="3"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView10"
                android:layout_column="5"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView14"
                android:layout_column="6"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView9"
                android:layout_column="1"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView8"
                android:layout_column="2"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView6"
                android:layout_column="3"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView7"
                android:layout_column="5"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView4"
                android:layout_column="6"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView18"
                android:layout_column="1"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView17"
                android:layout_column="2"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView16"
                android:layout_column="3"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView15"
                android:layout_column="5"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView19"
                android:layout_column="6"
                android:nestedScrollingEnabled="false"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="false">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView23"
                android:layout_column="1"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView22"
                android:layout_column="2"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView21"
                android:layout_column="3"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView20"
                android:layout_column="5"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView24"
                android:layout_column="6"
                android:src="@drawable/blog_dp_5058985_7848593_tr_woda" />

        </TableRow>

</TableLayout>

Upvotes: 0

Views: 92

Answers (1)

csenga
csenga

Reputation: 4114

I can comparing two imageView? eg image.get(1).getdrawable()==image.get(2).getdrawable()?

No, by this way it just comparing whether they are the same object or not. In this case this will be false. But, if you want to compare the images of the imageviews, then you should get theirs bitmap then use sameAs method.

        //comapre objects returns false
        Log.i("EQ", (imageList.get(0).getDrawable().equals(imageList.get(1).getDrawable())) + "");
        Log.i("EQ", imageList.get(0).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable@89c323c
        Log.i("EQ", imageList.get(1).getDrawable().toString()); //android.graphics.drawable.BitmapDrawable@837dbc5

        BitmapDrawable bitmapDrawable0 = ((BitmapDrawable) imageList.get(0).getDrawable());
        Bitmap bitmap0 = bitmapDrawable0 .getBitmap();

        BitmapDrawable bitmapDrawable1 = ((BitmapDrawable) imageList.get(1).getDrawable());
        Bitmap bitmap1 = bitmapDrawable1 .getBitmap();

        //comapre the image returns true
        Log.i("EQ2", Boolean.toString(bitmap0.sameAs(bitmap1)));

Where i called toString() it shows that, they are not the same object, although they are holding the same image as sameAs indicating.

Note: instead of equals() method, "==" operator would do the same, there is no difference

Upvotes: 1

Related Questions