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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:04:15+00:00 2026-06-01T19:04:15+00:00

I have an InfoListAdapter that uses the following code to populate views in the

  • 0

I have an InfoListAdapter that uses the following code to populate views in the list:

    public InfoListAdapter(final Context context) {
        super(context, 0);
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.info_list_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.populateViews(getItem(position));

        return convertView;
    }
}

I am wondering how I can follow this ViewHolder pattern and still add an onClickListener that will launch another activity DetailListActivity when clicked. My stragey was to make the mListener change using the existing populateViews method.

Needless to say it does not work. I think part of the problem here is that since mListener is null when I set the onClickListener, that reference is retained even after I change the value of the mListener. But the deeper question is how do I set something like this up, where I can use the ViewHolder pattern and let populateViews do the decoration (in terms of adding a listener to the click action)?

class ViewHolder {
    private TextView mTextViewDisplayName;
    private OnClickListener mListener;
    private Context mContext;

    public ViewHolder(final View view) {
        mTextViewDisplayName = (TextView) view.findViewById(R.id.tv_displayname);
        view.setOnClickListener(mListener);
        mContext = view.getContext();
    }

    public void populateViews(final Info infoItem) {
        mTextViewDisplayName.setText(infoItem.displayName);

        mListener = new OnClickListener() {

        public void onClick(View view0) {
                Intent mIntent = new Intent(mContext, DetailActivity.class);
                mIntent.putExtra(EMService.INTENT_EXTRA_DETAIL_VIEW_SOMEPARAM, 0);
                startActivityForResult(mIntent, 0);
            }
        };
    }
}
  • 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-01T19:04:17+00:00Added an answer on June 1, 2026 at 7:04 pm

    In your parent activity/fragment that houses your ListView you can implement OnItemClickListener and handle your clicks there. This way you don’t have to assign a click handler for every single view you instantiate.

    Ex. Lets say you have a ListActivity class named MyListActivity (I’m so creative)

    public class MyListActivity extends ListActivity implements OnItemClickListener
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)
        {
            Intent intent = new Intent(this, DetailActivity.class);
            intent.putExtra(EMService.INTENT_EXTRA_DETAIL_VIEW_SOMEPARAM, 0);
            startActivityForResult(intent, 0);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Have the following code: $(#blogs).mouseover( function () { $(this).addClass(hover); $(#home).removeClass(hover); $(#homepages).removeClass(hover); $(#apps).removeClass(hover); $(#facebook).removeClass(hover); $(#kontakt).removeClass(hover);
Have the following code: String s= v.request(engine/?key=, P4z72NmBa91&method=load); JSONParser parser = new JSONParser(); Object
Have got the following HAML code, combined with Markdown: %h2.slogan.align-center :markdown No more big
Have the following code. The height is variable so the height of the floating
Have a Facebook app that is failing as of this morning with the following
Have deployed numerous report parts which reference the same view however one of them
have 2 questions : A computer with 32-bit address uses 2-level page table (9
Have a chat room, issue is, is that when you submit something, the message
have defined a Java Interface with the annotation @WebService Compiled the code which went

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.