【问题标题】:Android Listview Items not redrawn when they scroll off the screen in FroyoAndroid Listview 项目在 Froyo 中滚动出屏幕时未重绘
【发布时间】:2010-10-12 23:54:27
【问题描述】:

我有一个列表视图,当滚动并且项目离开屏幕时,当我滚动回它们(文本和复选框)时,它们不会重绘。事实上,列表视图中屏幕底部的项目在滚动到它们时永远不会被绘制。这只发生在 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);
}

【问题讨论】:

  • 什么是 checkListItemAdapter?
  • @Android Addict:你为什么打电话给setScrollingCacheEnabled()layoutItem 来自哪里? layoutChecklists 是什么?
  • checkListItemAdapter 是一个适配器扩展器,专门用于我的列表设计。
  • 我对 setScrollingCacheEnabled() 的想法将解决我面临的问题。
  • layoutItem 是一个已定义的布局,我在该类的另一部分引用它并使用您在此处看到的 sn-p 传递给过程。与 layoutItem 一样,layoutChecklists 是代码中引用的已定义布局。

标签: android listview android-2.2-froyo


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多