3

我有一个布局复杂的列表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设置setProgressProgressBar. 但我没有处理字符串progressProgressBar.

4

1 回答 1

8

You need to find out if the ViewBinder is called for the ProgressBar and set its progress(from the data parameter(the data from column progress in your case)):

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
}

EDIT : I've seen in your addItem method that you do:

temp.put("progress", name);// Why do you set again the name as progress?!?

I think what you should set here is the progress parameter:

temp.put("progress", progress);

Then in the ViewBinder:

if (view.getId() == R.id.progressBar1) {
   Integer theProgress = (Integer) data;
   ((ProgressBar)view).setProgress(theProgress); 
   return true;
}
于 2012-05-01T12:26:53.627 回答