2013-03-05 60 views
0

这是我正在处理的应用程序中ListView的右侧。出现在ListView的第一个条目中的图像不应出现

There are two stars here. There should only be one.

正如你所看到的,ImageView显示星级显示了两次9项的列表。

这是这ListViewCursorAdapter使用BindView方法:

@Override 
public void bindView(View v, Context context, Cursor c) { 
    AQuery aq = new AQuery(v); 
    MyDatabaseHelper helper = new MyDatabaseHelper(context); //Used for various bits of text-setting. Is largely unrelated to the question. 
    boolean isDefault = (c.getShort(c.getColumnIndexOrThrow(MyDatabaseHelper.DEFAULT))==1); 
    Log.d("Binding account to view", "Entry "+currentID+"isDefault: "+isDefault); 
    v.setTag(isDefault); 
    if (isDefault) { 
     aq.id(R.id.favStar).visible(); //favStar defaults to GONE. 
    } 
    helper.close(); 
} 

正如你所看到的,它会检查,如果在我的数据库中的列在一个变量的读数为1个,然后存储布尔数学题位。使用该变量时,它会标记View,报告该变量的状态,然后当且仅当该变量为真时,才会显示星标。

这是从列表输出日志被填充,然后加入第九项:

02-28 10:50:23.381: D/Binding account to view(20759): Entry 1isDefault: false 
02-28 10:50:23.397: D/Binding account to view(20759): Entry 2isDefault: false 
02-28 10:50:23.413: D/Binding account to view(20759): Entry 3isDefault: false 
02-28 10:50:23.420: D/Binding account to view(20759): Entry 4isDefault: false 
02-28 10:50:23.436: D/Binding account to view(20759): Entry 5isDefault: false 
02-28 10:50:23.444: D/Binding account to view(20759): Entry 6isDefault: false 
02-28 10:50:23.459: D/Binding account to view(20759): Entry 7isDefault: false 
02-28 10:50:23.475: D/Binding account to view(20759): Entry 8isDefault: true 
02-28 10:50:23.498: D/Binding account to view(20759): Entry 1isDefault: false 
02-28 10:50:23.506: D/Binding account to view(20759): Entry 2isDefault: false 
02-28 10:50:23.530: D/Binding account to view(20759): Entry 3isDefault: false 
02-28 10:50:23.553: D/dalvikvm(20759): GC_CONCURRENT freed 122K, 2% free 11069K/11271K, paused 3ms+15ms, total 43ms 
02-28 10:50:23.553: D/Binding account to view(20759): Entry 4isDefault: false 
02-28 10:50:23.577: D/Binding account to view(20759): Entry 5isDefault: false 
02-28 10:50:23.592: D/Binding account to view(20759): Entry 6isDefault: false 
02-28 10:50:23.600: D/Binding account to view(20759): Entry 7isDefault: false 
02-28 10:50:23.616: D/Binding account to view(20759): Entry 8isDefault: true 

(添加第9个项只是增加了一个“入口9isDefault:假”的日志输出)

有谁能告诉我为什么我的列表中有一颗星出现在调试日志声明不应该出现的地方?此ListView出现在ListFragment中,也不包含ListFragment的活动对任何地方的R.id.favStar进行任何引用。

为了进一步阐述:我也尝试过不使用AQuery(使用FindViewById()setVisible()),结果没有改变为调试日志中显示的预期结果。 被窃听的星星总是出现在第一个位置,并且只有当列表中的其他星星应该出现时才会出现。(在设置ISDEFAULT = 1之前,DatabaseHelper类会将数据库中的所有项目设置为ISDEFAULT = 0)。更奇怪的是,使用ADT为您提供主/细节流的模板,此错误无法在Nexus 7上复制,但可以在我的Galaxy Nexus和模拟器上找到。

回答

1

如果isDefault为假,您绝不隐藏您的favStar视图。如果您的元素设置为true并显示该视图,则该明星将会显示,直到您再次隐藏它。当视图被回收时,即使没有设想,明星仍会显示。你不会在你的nexus 7上看到它,因为你的屏幕可能没有足够的元素,因为它的屏幕比手机高。无论如何,将您的代码更改为类似的内容应该可以解决它:

if (isDefault) { 
    aq.id(R.id.favStar).visible(); //favStar defaults to GONE. 
} else { 
    //set favStar to View.GONE here 
}