Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4339098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:10:16+00:00 2026-05-21T11:10:16+00:00

Well, this is my first topic around here, but that shouldn’t matter so far.

  • 0

Well, this is my first topic around here, but that shouldn’t matter so far.

My question is: How can I handle Views with similar IDs (example: R.id.View1, View2, View3, ..) in a loop & how can I give each of them a different picture out of my drawable resource (example: R.drawable.pic1, pic2, pic3, ..)?

I haven’t found an answer on this yet, thought I didn’t rly know what to look for in google :P.

To give you a better view about my topic, here is my code:

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="492px"
    >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <ImageView
            android:id="@+id/puzzletile_r1_c1"
            android:layout_width="82px"
            android:layout_height="82px"
            />
        <ImageView
            android:id="@+id/puzzletile_r1_c2"
            android:layout_width="82px"
            android:layout_height="82px"
            />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <ImageView
            android:id="@+id/puzzletile_r2_c1"
            android:layout_width="82px"
            android:layout_height="82px"
            />
        <ImageView
            android:id="@+id/puzzletile_r2_c2"
            android:layout_width="82px"
            android:layout_height="82px"
            />
    </LinearLayout>
</LinearLayout>

There’re alot more Linears & ImageViews inside that file, but I deleted them for a better overview.

package fast.games.puzzleme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

    public class GameActivity extends Activity{

        // Declare variable for checking if the custom Title is supported
        boolean customTitleSupported;

        public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);

               setContentView(R.layout.playground);

        }
    }

My general idea was to do sth like this:

for(i = 0; i<= 10; i++){
Imageview iv = (ImageView)this.findViewById(R.id.pic_+i);
iv.setImageResource(R.drawable.img_+i)
}

Thought it doesn’t work like that >.<

Is there any way to accomplish that?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:10:16+00:00Added an answer on May 21, 2026 at 11:10 am

    You cannot generate view ids like that, but you can findViewByTag() and specify android:tag in playground.xml file. But there’s a way to get resource id by name. Just call getResources().getIdentifier("img_" + i, "drawable", getPackageName()) and you’ll get img_xxx drawable’s id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time asking a question here. I tried to be well
I do realize that this question seems very well known, but since I don't
First, I don't know where to ask this question. Well this is programming QA
This is my first experience with javascript, and... Well... Ugh. Here's what's happening: function
Well, first of all sorry about this question it must be pretty straight forward
There's a bunch on this topic, but I havn't found an instance that applies
Im sure this topic has been broached before but here goes. My attemp is
well this is my problem i use 2 source first query (select * from
This is my first time playing with Active Directory, as well as the Ajax
My title sums this up pretty well. My first though it to provide a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.