I have a ListView to observe messages between different electronic devices in a car. For some parts i only get a few datasets per second but on others this could go up to 1000.
The ListView is only part of my App, the other part is working with the massive amount of data quite well.
i use a customized ArrayAdapter with following getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
itemp = items.get(position);
if (convertView == null) {
tvs = new TextView[7];
convertView = LayoutInflater.from(mycontext).inflate(container, parent,false);
tvs[0] = (TextView) convertView.findViewById(R.id.rd_l_c_messzeit);
tvs[1] = (TextView) convertView.findViewById(R.id.rd_l_c_frameid);
tvs[2] = (TextView) convertView.findViewById(R.id.rd_l_c_can);
tvs[3] = (TextView) convertView.findViewById(R.id.rd_l_c_dlc);
tvs[4] = (TextView) convertView.findViewById(R.id.rd_l_c_typ);
tvs[5] = (TextView) convertView.findViewById(R.id.rd_l_c_data);
tvs[6] = (TextView) convertView.findViewById(R.id.rd_l_c_datum);
convertView.setTag(tvs);
convertView.setEnabled(false);
}else {
tvs=(TextView[]) convertView.getTag();
}
if (itemp != null) {
strings = itemp.getStrings();
if (container == R.layout.rawdata_list_container) {
for (int i = 0; i < 7; i++) {
if (tvs[i] != null) {
tvs[i].setText(strings[i]);
}
}
tvs[3].setText(strings[3].substring(1));
}
}
return convertView;
}
My Rowlayout is just 7 Textviews so my Holder is a TextView Array items is my ArrayList with DataItems where the getStrings() returns a Stringarray size 7
The contents of the StringArray are defined in background threads which are tested and run smoothly.
Calling 1000 times notifyDataSetChanged() causes a complete stop and my UI is not responsive so i buffered the DataItems in a backgroundthread and update the real adapter only 5 times a second.
Runnable updaterun=new Runnable(){
@Override
public void run()
{
for(RawdataItem rdi:templist)
{
tracelist.add(1,rdi);
if(tracelist.size()>500)
{
tracelist.remove(500);
}
}
for(RawdataItem rdi:templistlight)
{
count = 0;
newtrl=true;
for (RawdataItem r : tracelistlight) {
if (rdi.lid == r.lid) {
tracelistlight.set(count,rdi);
newtrl=false;
break;
}
count++;
}
if(newtrl) {
tracelistlight.add(rdi);
Collections.sort(tracelistlight);
}
}
update_rdl();
templist.clear();
templistlight.clear();
updatehandler.postDelayed(updaterun, 200);
}
};
the tracelist is to display all items and the light list is to display every id only once update_rdl just calls notifidatasetchanged for both lists;
I would be glad for any and all help you could give me.