ViewBinder创建随机内容 [英] ViewBinder creates random content
问题描述
我有一个奇怪的ViewBinder behavoir。所有的工作在TextViews不错。随着的CheckBox(在我的code删除),并自定义部件progressChart值不存储在列表右侧现在的位置,当我向下滚动和/或再升。一切似乎很随意。但TextViews是总是正确的。
这里是我的code:
I have strange behavoir in a ViewBinder. All works good on TextViews. With CheckBoxes (removed in my code) and custom widgets progressChart the values are not stored in the right postion of the List when I scroll down and/or up again. All seems very random. But TextViews are always correct. Here is my code:
SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if (view.getId() == R.id.progress) {
ProgressChart progressChart = (ProgressChart) view;
progressChart.setVisibility(ImageButton.GONE);
} else {
if (x.substring(0, 1).equals("1")) {
int theProgress = Integer.parseInt(x.substring(1));
progressChart.setProgressDarkRed(theProgress);
}
}
if (view.getId() == R.id.textView1) {
TextView textView = (TextView) view;
textView.setText((String) data);
}
return true;
}
};
simpleAdapter.setViewBinder(viewBinder);
setListAdapter(simpleAdapter);
任何帮助,高度AP preciated
Any help is highly appreciated
我发现了一个类似的问题,但答案犯规适合我的code。
问题与viewBinder
I found a similar problem but the answer doesnt fit to my code. Problem with the viewBinder
推荐答案
这是因为鉴于回收。
您需要创建一个对象来保存你的复选框的状态,并在您的适配器设置你的看法。
You need to create an object to hold the status of your checkboxes and set your views from that in your adapter.
我不认为它可以在viewbinder来完成,因为位置不是在传递给它(但说实话,我从来没有尝试过)。
I don't think it can be done in the viewbinder since the position is not passed in to it (but to be honest I've never tried)..
您可能不得不做,在 getView
。
You will probably have to do it in getView
.
下面是我的previous回答一个链接,我展示了如何去做一个SimpleCursorAdapter(它可以进行修改,以APPY到arrayadapter太)。 SO回答
Here is a link to a previous answer of mine where I show how to go about it with a SimpleCursorAdapter (it can be modified to appy to an arrayadapter too). SO Answer
这篇关于ViewBinder创建随机内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!