Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory usage in ListView with dynamic layout data
    primarykey
    data
    text
    <p>I am working on a custom ListView with nested data for each row. I want to show a person's name with a checkbox for each line, and then dynamically add sub-rows to the ListView for 1-to-many phone numbers associated with that person.</p> <p>That is currently working. However, with larger datasets I am seeing slowdowns and crashes due to intense memory usage. Is there a better way to accomplish what I'm trying to do? </p> <p>Here is an example of what I want to see:</p> <pre><code>[] Joe Smith [] 1-555-444-3333 [] 1-555-777-6655 [] 1-555-234-3232 [] John Doe [] 1-555-882-3434 [] Someone Else [] 1-555-949-0304 [] 1-555-392-4433 </code></pre> <p>Here is the code I'm currently using in the getView() function for my ArrayAdapter. I tried to clean it up some, so if there are any compile errors, they are likely a typo from my cleanup.</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; ViewHolder holder; CustomContactInfo custom_contact = getItem(position); if(convertView==null){ inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); vi = inflater.inflate(R.layout.name_line, null); holder=new ViewHolder(); holder.contact_name=(TextView)vi.findViewById(R.id.contact_name); holder.cb_selected=(CheckBox)vi.findViewById(R.id.contact_check); holder.phone_numbers=(LinearLayout)vi.findViewById(R.id.phone_number_container); vi.setTag(holder); } else { holder=(ViewHolder)vi.getTag(); } // Set the name of the contact on the main line holder.contact_name.setText(custom_contact.name); // Add the custom views for each phone number holder.phone_numbers.removeAllViews(); for (Phone p : custom_contact.phones) { View v = this.inflater.inflate(R.layout.phone_number, null); CheckBox cb = (CheckBox)v.findViewById(R.id.phone_check); TextView number = (TextView)v.findViewById(R.id.phone_number); number.setText(p.phone_num); holder.phone_numbers.addView(v); } return vi; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload