Java 类android.widget.SimpleAdapter.ViewBinder 实例源码

项目:stynico    文件:HCActivity.java   
public void initAdapter()
   {
items = new ArrayList<Map<String,Object>>(); 
//实例化一个适配器  
adapter = new SimpleAdapter(HCActivity.this, items,
                R.layout.hc_list_item,
                new String[]{"imageItem", "fileName","delay","filePath"},
                new int[]{R.id.image_item, R.id.hc_tv_filename,R.id.tv_delay}
                );  

list.setAdapter(adapter);  
adapter.setViewBinder(new ViewBinder(){

    @Override
    public boolean setViewValue(View p1, Object p2, String p3)
    {
        if (p1 instanceof ImageView && p2 instanceof Bitmap)
        {
        ImageView iv = (ImageView) p1;
        iv.setImageBitmap((Bitmap) p2);
        return true;
        }
        else
        return false;

    }
    });
   }
项目:aws-sdk-android-samples    文件:GlobalRecordActivity.java   
private void initUI() {
    simpleAdapter = new SimpleAdapter(this, recordItems,
            R.layout.record_item, new String[] {
                    MAP_KEY_NAME,
                    MAP_KEY_SCORE
            }, new int[] {
                    R.id.textViewUserName,
                    R.id.textViewScore
            });
    simpleAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data,
                String textRepresentation) {
            switch (view.getId()) {
                case R.id.textViewUserName:
                    TextView name = (TextView) view;
                    name.setText((String) data);
                    return true;
                case R.id.textViewScore:
                    TextView score = (TextView) view;
                    score.setText(String.valueOf((Integer) data));
                    return true;
            }
            return false;
        }
    });
    getListView().setAdapter(simpleAdapter);
    new GetRecordsTask().execute();
}
项目:CSipSimple    文件:CodecsFragment.java   
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    prefsWrapper = new PreferencesWrapper(getActivity());
    useCodecsPerSpeed  = SipConfigManager.getPreferenceBooleanValue(getActivity(), SipConfigManager.CODECS_PER_BANDWIDTH);
    initDatas();
    setHasOptionsMenu(true);



    // Adapter
    mAdapter = new SimpleAdapter(getActivity(), codecsList, R.layout.codecs_list_item, new String[] {
            CODEC_NAME,
            CODEC_NAME,
            CODEC_PRIORITY
    }, new int[] {
            R.id.line1,
            R.id.AccCheckBoxActive,
            R.id.entiere_line
    });

    mAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            if (view.getId() == R.id.entiere_line) {
                Log.d(THIS_FILE, "Entiere line is binded ");
                TextView tv = (TextView) view.findViewById(R.id.line1);
                ImageView grabber = (ImageView) view.findViewById(R.id.icon);
                CompoundButton checker = (CompoundButton) view.findViewById(R.id.AccCheckBoxActive);
                checker.setOnCheckedChangeListener(CodecsFragment.this);
                if ((Short) data == 0) {
                    tv.setTextColor(Color.GRAY);
                    grabber.setVisibility(View.GONE);
                    checker.setChecked(false);
                } else {
                    tv.setTextColor(Color.WHITE);
                    grabber.setVisibility(View.VISIBLE);
                    checker.setChecked(true);
                }
                return true;
            }else if(view.getId() == R.id.AccCheckBoxActive) {
                view.setTag(data);
                return true;
            }
            return false;
        }

    });

    setListAdapter(mAdapter);
    registerForContextMenu(getListView());
}
项目:AppCrawler    文件:MainActivity.java   
private boolean refreshAppListView() {

        // Get installed packages
        ArrayList<HashMap<String, Object>> appList = new ArrayList<HashMap<String, Object>>();
        if (sPkgInfoList == null) {
            sPkgInfoList = mPkgMgr.getInstalledPackages(0);
        }

        for (PackageInfo pkg : sPkgInfoList) {

            // Skip Ourself
            if (pkg.packageName.equalsIgnoreCase(getPackageName()))
                continue;

            // Skip Android packages
            if (mCheckBoxHideAndroid.isChecked()) {
                if (pkg.packageName.contains(PKG_PREFIX_ANDROID))
                    continue;
            }

            // Skip Google packages
            if (mCheckBoxHideGoogle.isChecked()) {
                if (pkg.packageName.contains(PKG_PREFIX_GOOGLE))
                    continue;
            }

            HashMap<String, Object> mapApp = new HashMap<String, Object>();
            mapApp.put(APP_PKG, pkg.packageName);
            mapApp.put(APP_NAME, pkg.applicationInfo.loadLabel(mPkgMgr));
            mapApp.put(APP_ICON, pkg.applicationInfo.loadIcon(mPkgMgr));
            appList.add(mapApp);
        }

        // Bind ListView with content adapter
        SimpleAdapter appAdapter = new SimpleAdapter(this, appList, R.layout.app_list_item,
                new String[] {
                        APP_NAME, APP_PKG, APP_ICON
                },
                new int[] {
                        R.id.appName, R.id.appPackage, R.id.appIcon
                });

        appAdapter.setViewBinder(new ViewBinder() {
            public boolean setViewValue(View view, Object data, String textRepresentation) {
                if (view instanceof ImageView && data instanceof Drawable) {
                    ImageView iv = (ImageView) view;
                    iv.setImageDrawable((Drawable) data);
                    return true;
                }
                else
                    return false;
            }
        });

        mListView.setAdapter(appAdapter);

        return true;
    }