开发者

Android Listview Items not redrawn when they scroll off the screen in Froyo

开发者 https://www.devze.com 2023-01-20 10:50 出处:网络
I have a listview that when scrolled and the items go off of the screen they are not redrawn when I scroll back to them (the text and checkbox).In fact, items that are off the bottom of the screen in

I have a listview that when scrolled and the items go off of the screen they are not redrawn when I scroll back to them (the text and checkbox). In fact, items that are off the bottom of the screen in the listview never get drawn when scrolling to them. This only happens in Froyo. Any other version it works just fine. I have checked and the data is there as expected in the adapter when the getItem method is called, it is just not visible. The listview item is there (it's occupying the same amount of screen space per item), I just cannot see the text or checkbox once scrolled off screen and back on again.

My code is such:

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);
}


I resolved this by using a ViewGroup (preferred method per documentation) instead of creating all of the views in code.

0

精彩评论

暂无评论...
验证码 换一张
取 消