如何使用SimpleAdapter.ViewBinder? [英] How to use SimpleAdapter.ViewBinder?

查看:203
本文介绍了如何使用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 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;
}

这篇关于如何使用SimpleAdapter.ViewBinder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆