行ごとにネストされたデータを持つカスタム ListView に取り組んでいます。行ごとにチェックボックスを使用して人の名前を表示し、その人に関連付けられた 1 対多の電話番号の ListView にサブ行を動的に追加したいと考えています。
それは現在働いています。ただし、大規模なデータセットでは、メモリ使用量が多いため、速度が低下したりクラッシュしたりします。私がやろうとしていることを達成するためのより良い方法はありますか?
これが私が見たいものの例です:
[] 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
ArrayAdapter の getView() 関数で現在使用しているコードを次に示します。いくつかクリーンアップしようとしたので、コンパイル エラーがある場合は、クリーンアップによるタイプミスである可能性があります。
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;
}