0

我有一个列表视图,当滚动并且项目离开屏幕时,当我滚动回它们(文本和复选框)时,它们不会重绘。事实上,列表视图中屏幕底部的项目在滚动到它们时永远不会被绘制。这只发生在 Froyo 中。任何其他版本都可以正常工作。我已经检查过,当调用 getItem 方法时,适配器中的数据如预期的那样,只是不可见。列表视图项目在那里(每个项目占用相同数量的屏幕空间),一旦滚动离开屏幕并重新打开,我就看不到文本或复选框。

我的代码是这样的:

for(checklist cl : checkLists) {
    ArrayList<checklistItem> ChecklistItems = database.getChecklistItems(
                                                  cl.getId());

    ListView lv = new ListView(this);
    lv.setScrollingCacheEnabled(true);                  
    lv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 
                                        LayoutParams.WRAP_CONTENT));
    la = new checklistItemAdapter(this, layoutItem, ChecklistItems);      
    la.setActivity(this);
    lv.setAdapter(la);                

    TextView tv = new TextView(this);
    tv.setText(cl.getItemText());
    tv.setGravity(1);
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 50));
    tv.setBackgroundColor(Color.BLUE);
    tv.setTextSize(28);
    tv.setTextScaleX(2);
    tv.setTypeface(Typeface.DEFAULT_BOLD);
    tv.setTypeface(Typeface.SANS_SERIF);

    layoutChecklist = new LinearLayout(this);                
    layoutChecklist.setOrientation(1);
    layoutChecklist.addView(tv);
    layoutChecklist.addView(lv);

    layoutChecklists.addView(layoutChecklist);
}
4

1 回答 1

0

我通过使用 ViewGroup(每个文档的首选方法)而不是在代码中创建所有视图来解决这个问题。

于 2010-11-23T23:35:18.893 回答