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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:32:56+00:00 2026-05-23T13:32:56+00:00

my application on the first lunch uses 6.5mb, and then when I enter an

  • 0

my application on the first lunch uses 6.5mb, and then when I enter an activity with 3 tabs, with a tab that displays a listview, it uses 14 mb!!

This happened when I went from a “bad code” with SimpleAdapter to my Custom Adapter.

What I want is 2 strings on each side in a listview. the strings are in an array, here is the way I was using that people told me is an incorrect way to do:

String[] array= getResources().getStringArray(R.array.Names_List);

int lengthtmp= array.length;
for(int i=0;i<lengthtmp;i++)
{
    counter++;
    AddToList(array[i]);            
}

adapter = new SimpleAdapter(this,list,R.layout.start_row,new String[] {"number","suraname"},new int[] {R.id.Start_Numbering,R.id.Start_Name});


private void AddToList(String name) {
HashMap<String,String> temp = new HashMap<String,String>();


temp.put("number", Integer.toString(SortingPictures[counter-1]));

temp.put("suraname", name);
list.add(temp);

  }

With this code, the activity takes 10mb of ram. After changing my code to use a Custom adapter, it uses 14 mb:

 public class ListView_Start_Adapter extends BaseAdapter{
private String[] SuraNames;
private int[] PageNumber;
private Context mContext;
RelativeLayout relativeView;
TextView tv_SuraName;
TextView tv_PageNumber;
RelativeLayout.LayoutParams param;

public ListView_Start_Adapter(Context context, String[] SuraNames, int[] PageNumber){
    mContext=context;
    this.SuraNames=SuraNames;
    this.PageNumber=PageNumber;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return SuraNames.length;
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return SuraNames[arg0];
}

@Override
public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return PageNumber[arg0];
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    relativeView= new RelativeLayout(mContext);
    tv_SuraName = new TextView(mContext);
    tv_PageNumber = new TextView(mContext);

    tv_SuraName.setText(SuraNames[position]);
    tv_PageNumber.setText(Integer.toString(PageNumber[position]));

    param = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    relativeView.addView(tv_SuraName, param);
    relativeView.addView(tv_PageNumber);

    return relativeView;

}

  }

Can anyone tell me why so much ram used when using a Custom adapter? Is there something wrong with this Custom adapter?

EDIT1: Is this a better code that the one suggested by dziobas:

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

    if(convertView == null) {
        convertView = mInflater.inflate(R.layout.start_row, parent,false);
        holder=new ViewHolder();

        holder.tv_SuraName   =(TextView)convertView.findViewById(R.id.Start_Name);
        holder.tv_PageNumber = (TextView)convertView.findViewById(R.id.Start_Numbering);
        convertView.setTag(holder);
    } else {
        holder  = (ViewHolder) convertView.getTag();
    }

    holder.tv_SuraName.setText(SuraNames[position]);
    holder.tv_PageNumber.setText(Integer.toString(PageNumber[position]));

    return convertView;
}

I get ExceptionNullPointer in this line: ” convertView = mInflater.inflate(R.layout.start_row, parent,false);
” Why?

  • 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-23T13:32:57+00:00Added an answer on May 23, 2026 at 1:32 pm

    You’re not recycling view in getView.

    It’ll much better like this:

    public class ListView_Start_Adapter extends BaseAdapter {
        private String[]            SuraNames;
        private int[]               PageNumber;
        RelativeLayout.LayoutParams param;
        Context                     mContext;
    
        public ListView_Start_Adapter(Context context, String[] SuraNames, int[] PageNumber) {
            mContext        = context;
            this.SuraNames  = SuraNames;
            this.PageNumber = PageNumber;
            param           = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
            param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
    
        @Override
        public int getCount() {
            return SuraNames.length;
        }
    
        @Override
        public Object getItem(int arg0) {
            return SuraNames[arg0];
        }
    
        @Override
        public long getItemId(int arg0) {
            return PageNumber[arg0];
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder     holder;
            RelativeLayout rowView;
    
            if(convertView == null) {
                //create view
                rowView              = new RelativeLayout(mContext);
                holder               = new ViewHolder();
                holder.tv_SuraName   = new TextView(mContext);
                holder.tv_PageNumber = new TextView(mContext);
                rowView.addView(holder.tv_SuraName, param);
                rowView.addView(holder.tv_PageNumber);
                rowView.setTag(holder);
            } else {
                //recycle view
                rowView = (RelativeLayout) convertView;
                holder  = (ViewHolder) convertView.getTag();
            }
    
            //fill views
            holder.tv_SuraName.setText(SuraNames[position]);
            holder.tv_PageNumber.setText(Integer.toString(PageNumber[position]));
    
            return rowView;
        }
    
        class ViewHolder {
            RelativeLayout relativeView;
            TextView       tv_SuraName;
            TextView       tv_PageNumber;
        }
    }
    

    And change view creation. Use LayoutInflater and use xml for layout.

    See this presentation for more info about listview adapter efficiency.

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

Sidebar

Related Questions

I've made a NSMutableArray for the EKCalendars that my application uses. On the first
I have an Android application for pre-Honeycomb devices that uses custom tabs to launch
I need to recognize first launch of my application or activity. At this time
i have a sencha touch application that uses a tabpanel, a beta version of
I am currently developing a debugger java application that uses JDI to connect to
There's Quicktime SDK for Windows, but any application that uses it needs quicktime runtime
I'm making my first D3D simple game. My game uses many images. This is
How can I detect the very first time launch of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
When my application first runs I'm using some simple code to read in some
in my application the first view is an UIView with a couple of uilabel

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.