如何使用SimpleAdapter.ViewBinder?如何使用、SimpleAdapter、ViewBinder

由网友(幼稚园干饭第一名)分享简介:我有一个复杂的布局列表 R.layout.menu_row 。它由一个进度和文本字段。该适配器使用:I have a list with a complex layout R.layout.menu_row. It consists of a ProgressBar and a text field. The ada...

我有一个复杂的布局列表 R.layout.menu_row 。它由一个进度和文本字段。该适配器使用:

I have a list with a complex layout R.layout.menu_row. It consists of a ProgressBar and a text field. The adapter I use:

   SimpleAdapter simpleAdapter = new SimpleAdapter(this, getData(path),
            R.layout.menu_row, new String[] { "title", "progress" },
            new int[] { R.id.text1,R.id.progressBar1});

适配器知道如何通过其自身而不是 ProgressBars ,所以我写了一个复杂的数据粘合剂处理 TextViews

The adapter knows how to handle TextViews by it self but not ProgressBars, so I wrote a complex data binder:

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

现在我被困填充函数内部的映射。我需要设置字符串的值进步来的 setProgress 方法进度。但我没有得到一个处理字符串进步,并在进度

Now I'm stuck filling the mapping inside the function. I need to set the value of string progress to the setProgress method of the ProgressBar. But I don't get a handle to string progress and to the ProgressBar.

推荐答案

您需要找出是否 ViewBinder 是呼吁进度并设置它的进步(从数据参数(由列中的数据进步你的情况)):

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
}

编辑:我见过你的的addItem 方法,你做的:

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

我觉得你应该设置在这里是进步参数:

temp.put("progress", progress);

然后在 ViewBinder

if (view.getId() == R.id.progressBar1) {
   Integer theProgress = (Integer) data;
   ((ProgressBar)view).setProgress(theProgress); 
   return true;
}
阅读全文

相关推荐

最新文章