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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:19:51+00:00 2026-05-31T13:19:51+00:00

I have a custom listview that displays approx. 114 items, and in it I

  • 0

I have a custom listview that displays approx. 114 items, and in it I have a TextView (use as a link) so when the user clicks on the link it takes to another activity something like “read more…” kinda of link within a listview.

my question: Is the code below is optimized? in other words following the best practices? or horrible? since I will be creating around 114 activities, layouts and adding in AndroidManifest.xml

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row_custom_listview, null); 

    final TextView artist = (TextView)vi.findViewById(R.id.artist);   
    TextView link = (TextView)vi.findViewById(R.id.txtLink);  

    link.setOnClickListener(new OnClickListener() { 
        public void onClick(View v) {

    if (position == 0) {
       Intent intent_01 = new Intent(v.getContext(), more_01_Activity.class);    
       v.getContext().startActivity(intent_01); 
    }
    if (position == 1) {
       Intent intent_02 = new Intent(v.getContext(), more_02_Activity.class);    
       v.getContext().startActivity(intent_02); 
    }
    if (position == 3) {
       Intent intent_03 = new Intent(v.getContext(), more_03_Activity.class);    
       v.getContext().startActivity(intent_03); 
    }
         ...........
         ............
         ...........
         //goes upto 114 

        }
    }); 
    return vi;
}
  • 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-31T13:19:52+00:00Added an answer on May 31, 2026 at 1:19 pm
    findViewById 
    

    is a very expensive call which should be avoided as much as possible, fortunately there’s this idea of a ViewHolder, which you can use like this:

    create an inner class called ViewHolder

    private class ViewHolder {
      TextView link;
    }
    

    then inside your getView,

    ViewHolder viewHolder;
    if(convertView==null) {
      convertView = inflater.inflate...
      viewHolder = new ViewHolder();
      viewHolder.link = convertView.findViewById...
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder)convertView.getTag();
    }
    

    After that, it’s just a matter of using the holder items instead of the TextView link variable.
    so

    viewHolder.link.setOnClickListener...
    

    Also, instead of creating hundreds of different activities, you can code a more flexible activity that can adjust itself depending on the information it receives from the intent that launches it. example:

    inside onClickListener,

      Intent i = new Intent(context, MyFlexibleActivity.class);
      i.putExtra("position", position);
      startActivity(i);
    

    To get the position in the receiving Activity, do

    int position = getIntent().getIntExtra("position", default_value);
    

    and work on that information to display what you’re trying to accomplish with different activities.

    If you have more questions, feel free to ask in the comments.

    (update: string array example, from this page)
    on your strings.xml, instead of just one string per item, you can have a string array:

    Mercury
    Venus
    Earth
    Mars

    to use it,

    Resources res = getResources();
    String[] planets = res.getStringArray(R.array.planets_array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this ListView that displays a custom user control. The custom user control
I have an android app that displays a list of items in a Custom
I have a custom listview row that contains a number of textView components. Instead
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a custom listview with three items. One of them is like Add
I have a listview with custom row having a textview and a clickable image
In one of my Activities I have a ListView that displays a list of
I have a Custom ListView that contains a vertical LinearLayout of horizontal LinearLayouts for
I have a custom CursorAdapter that is taking items from a database and displaying
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides

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.