我有一个复杂布局R.layout.menu_row
的列表。它由ProgressBar
和文本字段组成。我使用的适配器:
SimpleAdapter simpleAdapter = new SimpleAdapter(this, getData(path),
R.layout.menu_row, new String[] { "title", "progress" },
new int[] { R.id.text1,R.id.progressBar1});
适配器知道如何自己处理TextViews
而不是ProgressBars
,所以我编写了一个复杂的数据绑定器:
SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
//here goes the code
if () {
return true;
}
return false;
}
现在我被困在函数内填充映射。我需要将字符串progress
的值设置为setProgress
的{{1}}方法。但我无法处理字符串ProgressBar
和progress
。
答案 0 :(得分:7)
您需要了解是否为ViewBinder
调用ProgressBar
并设置其进度(来自data
参数(来自您progress
列的数据) )):
SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view.getId() == R.id.progressBar1) {
// we are dealing with the ProgressBar so set the progress and return true(to let the adapter know you binded the data)
// set the progress(the data parameter, I don't know what you actually store in the progress column(integer, string etc)).
return true;
}
return false; // we are dealing with the TextView so return false and let the adapter bind the data
}
编辑:
我已经在你的addItem
方法中看到过:
temp.put("progress", name);// Why do you set again the name as progress?!?
我认为你应该在这里设置的是progress
参数:
temp.put("progress", progress);
然后在ViewBinder
:
if (view.getId() == R.id.progressBar1) {
Integer theProgress = (Integer) data;
((ProgressBar)view).setProgress(theProgress);
return true;
}