滚动时Android列表视图项崩溃了吗?

时间:2014-03-10 06:44:25

标签: android listview

我已动态创建了listiem文本。基于数组计数。第一次创建成功的视图。滚动列表视图时,所有项目都将折叠。有些时候文本视图显示重复。

下面我附上了我的适配器代码,请检查代码,

  public class Adapter extends BaseAdapter {

private ArrayList<PersonDataclass> list;
private Context ctx;
private LayoutInflater minflater;
private Viewholder holder;
private TextView[] Textview;

public Adapter(Context context, ArrayList<PersonDataclass> personList) {
    // TODO Auto-generated constructor stub
    minflater = LayoutInflater.from(context);
    ctx = context;
    list = personList;
}

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

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return list.get(arg0);
}

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

@Override
public View getView(int arg0, View view, ViewGroup arg2) {
    // TODO Auto-generated method stub
    if (view == null) {
        view = minflater.inflate(R.layout.list_item, null);
        holder = new Viewholder();
        holder.count = (TextView) view.findViewById(R.id.likecount);
        holder.flow_layout = (FlowLayout) view
                .findViewById(R.id.flow_layout);
        view.setTag(holder);
    } else {
        holder = (Viewholder) view.getTag();
    }
    try {
        holder.count.setText("Total votes count"
                + list.get(arg0).getPrcnt());
        int leftsize = list.get(arg0).getList().size();
        if (leftsize > 0 && leftsize <= 10) {
            Log.i("TAG", "left votelist if" + leftsize + "arg0" + arg0);
            Textview = new TextView[leftsize];
            for (int j = 0; j < leftsize; j++) {
                String str = "<font color=#409bf8>"
                        + list.get(arg0).getList().get(j).getRtuuname()
                        + "</font> <font color=#74869c>" + "voted"
                        + "</font> <font color=#dd095e>"
                        + list.get(arg0).getList().get(j).getRtval()
                        + "</font>" + ",";
                Textview[j] = new TextView(ctx);
                Textview[j].setText(Html.fromHtml(str));
                Textview[j].setTextSize(9);
                holder.flow_layout.addView(Textview[j]);
            }
        } else {
            Log.i("TAG", "left votelist else" + leftsize + "arg0" + arg0);
            Textview = new TextView[1];
            Textview[0] = new TextView(ctx);
            Textview[0].setText("total rates " + list.get(arg0).getPrcnt());
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
    return view;
}

private class Viewholder {
    private TextView count;
    private FlowLayout flow_layout;
}
 }

0 个答案:

没有答案