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 8544305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:31:30+00:00 2026-06-11T12:31:30+00:00

In my Android project, I need to find views in my Activity by their

  • 0

In my Android project, I need to find views in my Activity by their tags rather than their IDs. (If you ask me why I don’t simply use findViewById, It’s not my prefer, and is complicated to describe, but currently I can’t rely on R.id. constants!)
So far, to find views in my code, I have managed to use this successfully:

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

    setContentView(R.layout.index);
    mainViewGroup = (ViewGroup)getWindow().getDecorView();
    TextView indexCaption = (TextView) mainViewGroup.findViewWithTag("index_caption");
    // Now I have my TextView and can use it without problem
}

But now, the problem is my custom ArrayAdapter in the same activity:

    class IconicAdapter extends ArrayAdapter<String> {
    IconicAdapter() {
                    // How I can use Tag instead of R.layout.index_row_caption here?!!!
        super(IndexActivity.this, R.layout.index_row, R.id.index_row_caption, arrayList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = super.getView(position, convertView, parent);
                    // Some customizations...
        return (row);
    }
}

and index_row.xml for that IconicAdapter:

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_bg" >

<TextView
    android:id="@+id/index_row_caption"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/index_row_icon"
    android:layout_toRightOf="@+id/index_row_search"
    android:gravity="right"
    android:tag="index_row_caption"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/index_row_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:tag="index_row_icon" />

<ImageView
    android:id="@+id/index_row_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:src="@drawable/index_row_search"
    android:tag="index_row_search" />

How I can avoid using R.id.index_row_caption in the constructor and replace it with something related to its tag?

EDIT: At last, I have ended up to this code and it worked great: (credits and bounty goes for pawelzieba who helped me on this)

    class IconicAdapter extends ArrayAdapter<String> {
    IconicAdapter() {
        super(IndexActivity.this, R.layout.index_row, 0, arrayList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view;
        if (convertView == null) {
            LayoutInflater mInflater = IndexActivity.this.getLayoutInflater();
            view = mInflater.inflate(R.layout.index_row, parent, false);
        } else {
            view = convertView;
        }

        //find views
        TextView text = (TextView) view.findViewWithTag("index_row_caption");

        //fill views with data
        text.setText(arrayList.get(position));          

        return view;
    }
}
  • 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-06-11T12:31:31+00:00Added an answer on June 11, 2026 at 12:31 pm

    Extend ArrayAdapter and override getView() method.

    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
    
        if (convertView == null) {
            view = mInflater.inflate(R.layout.index_row, parent, false);
        } else {
            view = convertView;
        }
    
        //find views
        TextView text = (TextView) view.findViewWithTag("index_row_caption");
    
        //fill views with data
        //example:
        T item = getItem(position);
        text.setText(item.toString());
    
    
        return view;
    }
    

    Then row resource id passed to constructor is unused.

    To get better performance use View Holder Pattern to call findViewWithTag only once on create row’s view: http://www.vogella.com/articles/AndroidListView/article.html#adapterperformance_hoder

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

Sidebar

Related Questions

I am developing an android app for my project, I need to find room
My android app project need to add a new function of saving the click
I'm doing a Get and Post method for an android project and I need
I am working on android applications. In my project I need to create Listview.
I have started a new Android empty project. Where can i find the graphical
My problem is that i have an Android Class project and i need to
I have an Android project in Eclipse that I need to change the min
I am working on an android project in which i need to send two
I need to find a way to encrypt/decrypt an images in Android.I'm new in
I have an Android project where I need to build a client app to

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.