How to use SimpleAdapter.ViewBinder?

后端 未结 1 650
盖世英雄少女心
盖世英雄少女心 2021-01-06 13:27

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:

   SimpleA         


        
相关标签:
1条回答
  • 2021-01-06 13:48

    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;
    }
    
    0 讨论(0)
提交回复
热议问题