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

  • Home
  • SEARCH
  • 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 5847237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:41:24+00:00 2026-05-22T12:41:24+00:00

I have written a ListActivity class that uses a custom ArrayAdapter and Holders. I

  • 0

I have written a ListActivity class that uses a custom ArrayAdapter and Holders. I want to be able to access the TextView’s stored in each row, but have been unsuccessful. Here’s the pertinent ArrayAdapter code:

EDIT: wrote an inefficient hack to solve it


class SuperNewAdapter extends ArrayAdapter {

public View getView(int position, View convertView, ViewGroup parent) {
  // RowHolder is a simple inner class that stores two TextViews and a CheckBox
  RowHolder holder = new RowHolder();
  if (convertView == null) {
    convertView = layoutInflater.inflate(R.layout.listrow, null);
    holder.titleText = (TextView) convertView.findViewById(R.id.textTitle);
    holder.bottomText = (TextView) convertView.findViewById(R.id.textDescription;
    holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
    convertView.setTag(holder);
} else {
    holder = (RowHolder) convertView.getTag()
}
  holder.titleText.setText(stringArr1[position]);
  holder.bottomText.setText(stringArr2[position]);

  // Array to futilely attempt to get a reference to each textView
  titleTextArr.add(holder.titleText);
  /////////////////HACK ATTACK! rows is an ArrayList of Holders
  boolean flag=true;
  for (int i = 0; i < rows.size(); i++) {
    if (rows.get(i) == holder)
    flag=false;
   }
  if (flag) rows.add(holder);

  return convertView;
}

I have tried storing the Holders (is there more than one?) and also storing the TextViews and CheckBoxes in separate arrays, but each element in the array is the same element. The
ListActivity code :


public class SuperNewListActivity extends ListActivity {
  //used in the Adapter's getView() to store elements
  public ArrayList titleTextArr = new ArrayList();

public void onListItemClick(View v, int position, long id) { // always prints the same thing while position varies System.out.println(titleTextArr.get(position)); } }


I also tried using convertView.getTag(position), to no avail. How do I get those widgets so I can modify them? I need my widgets. widgets. widgets. Thanks for looking.

  • 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-22T12:41:25+00:00Added an answer on May 22, 2026 at 12:41 pm

    The following should work fine. From your getView() method:

    class SuperNewAdapter extends ArrayAdapter {

    public View getView(int position, View convertView, ViewGroup parent) {
      // RowHolder is a simple inner class that stores two TextViews and a CheckBox
      RowHolder holder;
      if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.listrow, null);
        holder = new RowHolder();
        holder.titleText = (TextView) convertView.findViewById(R.id.textTitle);
        holder.bottomText = (TextView) convertView.findViewById(R.id.textDescription;
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
        convertView.setTag(holder);
      } else {
          holder = (RowHolder) convertView.getTag()
      }
      holder.titleText.setText(stringArr1[position]);
      holder.bottomText.setText(stringArr2[position]);
      return convertView;
    }
    

    And then when clicked:

    public void onListItemClick(View v, int position, long id) {
      Log.i("foo", "Title text: " + ((RowHolder)v.getTag).titleText.getText());
    }
    

    If you just care about the text, you could store that directly in the RowHolder as a String so you don’t need to retrieve it from the TextView widget.

    Or alternatively you really don’t need to use the holder at all for this, since you have the original array you used to populate the list:

    public void onListItemClick(View v, int position, long id) {
      Log.i("foo", "Title text: " + stringArr1[position]);
    }
    

    This latter form really matches how ListView is more often used — it is displaying some data set held in an array or cursor or such; the Adapter is responsible for transforming that data into the correct representation to show to the user; when an item is clicked, you know which thing in the data set (both the position and id) was clicked so can just go directly to the data set to retrieve its value.

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

Sidebar

Related Questions

I have written a DLL that uses MS Word to spell check the content
I have written an assembly I don't want other people to be able to
I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have written a class that will be used to store parameters in a
I have written an AIR Application that downloads videos and documents from a server.
I have written a site in Prototype but want to switch to jQuery. Any
I have written a watir script that downloads files. One of the files it
Have written all the code in a silverlight class library (dll) and linked this
I have written this function that will give me a monthly sum for two
I have written a universal app that's working fine on both iPhone (iPod Touch)

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.