我有一个应用程序,我在其中接受诸如没有用户之类的输入,并根据列表视图填充一些修复名称、电话...等。我使用 viewholder 来优化我的所有列表视图。除了加载用户数据的列表视图外,所有列表视图都可以正常工作。
从图片中您可以看到第一行和最后一行已加载,但中间两行未加载,并且确实需要很长时间才能加载。我提供给每一行的信息最初是相同的,并留给用户修改。这是我使用的代码。
public View getView(final int position, View convertView,final ViewGroup parent)
{
View rowview = convertView;
if(rowview == null)
{
ViewHolder viewholder = new ViewHolder();
final LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowview = inflater.inflate(R.layout.list_skeleton_people_expenses, parent, false);
viewholder.tv1 = (TextView)rowview.findViewById(R.id.name);
viewholder.tv2 = (TextView)rowview.findViewById(R.id.destination);
viewholder.tv3 = (TextView)rowview.findViewById(R.id.start);
viewholder.tv4 = (TextView)rowview.findViewById(R.id.phno);
viewholder.rowview = rowview;
rowview.setTag(viewholder);
}
else
{
ViewHolder holder = (ViewHolder) rowview.getTag();
UserData temp = objects.get(position);
holder.tv1.setText(temp.name);
holder.tv2.setText("Destination: "+temp.loc);
holder.tv3.setText("Start: "+start);
String phone_txt = objects.get(position).phno;
phone_txt = "("+phone_txt.substring(0, 3)+") "+phone_txt.substring(3, 6)+"-"+phone_txt.substring(6, 10);
holder.tv4.setText(phone_txt);
}
return rowview;
}
static class ViewHolder
{
TextView tv1,tv2,tv3,tv4;
View rowview;
}
提前致谢。