Example usage for android.widget SimpleAdapter setViewBinder

List of usage examples for android.widget SimpleAdapter setViewBinder

Introduction

In this page you can find the example usage for android.widget SimpleAdapter setViewBinder.

Prototype

public void setViewBinder(ViewBinder viewBinder) 

Source Link

Document

Sets the binder used to bind data to views.

Usage

From source file:org.exoplatform.shareextension.AccountsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    ArrayList<Map<String, ExoAccount>> data = new ArrayList<Map<String, ExoAccount>>(accounts.size());
    for (ExoAccount account : accounts) {
        Map<String, ExoAccount> map = new HashMap<String, ExoAccount>();
        map.put("ACCOUNT_DATA", account);
        data.add(map);/*from w  w  w . j a  v  a  2 s . co  m*/
    }
    String[] from = { "ACCOUNT_DATA" };
    int[] to = new int[] { R.id.share_account_item_layout };
    SimpleAdapter adapter = new SimpleAdapter(activity, data, R.layout.share_extension_account_item, from, to);
    adapter.setViewBinder(this);
    setListAdapter(adapter);
}

From source file:org.ohmage.prompt.multichoice.MultiChoicePrompt.java

@Override
public View getView(Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ListView listView = (ListView) inflater.inflate(R.layout.prompt_multi_choice, null);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);/* w  w w  .  j  ava  2  s .  com*/
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.multi_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    listView.setAdapter(adapter);

    if (mSelectedIndexes.size() > 0) {
        for (int index : mSelectedIndexes) {
            if (index >= 0 && index < mChoices.size())
                listView.setItemChecked(index, true);
        }
    }

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //SparseBooleanArray checkItemPositions = ((ListView)parent).getCheckedItemPositions();
            if (((ListView) parent).isItemChecked(position)) {
                mSelectedIndexes.add(Integer.valueOf(position));
            } else {
                mSelectedIndexes.remove(Integer.valueOf(position));
            }
        }
    });

    return listView;
}

From source file:fr.eoit.activity.fragment.blueprint.RequiredSkillInventionFragment.java

@Override
public void onLoadFinished(Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor)) {
        short encryptionSkillLevel = -1;
        int encryptionSkillId = -1;
        short datacore1SkillLevel = -1;
        short datacore2SkillLevel = -1;

        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

        boolean datacore1SkillSet = false;

        while (!cursor.isAfterLast()) {
            Map<String, Object> dataLine = new HashMap<String, Object>();

            int skillId = cursor.getInt(cursor.getColumnIndexOrThrow(InventionMapping.COLUMN_NAME_SKILL_ID));
            String skillName = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
            int skillLevel = 1;

            short userSkillLevel = Skills.getSkill(skillId);
            if (Skills.isEncryptionSkill(skillId)) {
                encryptionSkillLevel = userSkillLevel;
                encryptionSkillId = skillId;
            } else {
                if (datacore1SkillSet) {
                    datacore2SkillLevel = userSkillLevel;
                } else {
                    datacore1SkillLevel = userSkillLevel;
                    datacore1SkillSet = true;
                }/*from  ww  w  . ja va2s . com*/
            }

            boolean learnt = userSkillLevel >= skillLevel;

            dataLine.put(InventionMapping.COLUMN_NAME_LEARNT, learnt);
            dataLine.put(Item.COLUMN_NAME_NAME, skillName);
            dataLine.put(InventionMapping.COLUMN_NAME_SKILL_LEVEL, userSkillLevel);
            data.add(dataLine);

            cursor.moveToNext();
        }

        SimpleAdapter adapter = new SimpleAdapter(getActivity(), data, R.layout.required_skills_row, FROM, TO);

        adapter.setViewBinder(new RequiredSkillsViewBinder());
        ListView listView = (ListView) getView().findViewById(R.id.REQUIRED_SKILLS_LIST);
        listView.setAdapter(adapter);
        int count = cursor.getCount();
        int width = count * ((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 26,
                getResources().getDisplayMetrics()));
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                width);
        listView.setLayoutParams(lp);

        if (fragmentReference != null && fragmentReference.get() != null) {
            fragmentReference.get().updateInventionChances(encryptionSkillLevel, datacore1SkillLevel,
                    datacore2SkillLevel);
            fragmentReference.get().setEncryptionSkillId(encryptionSkillId);
        }
    }
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

private void setupViewBinders(SimpleAdapter adapter, final int stdColorResource, final int fixColorResource) {
    adapter.setViewBinder(new SimpleAdapter.ViewBinder() {

        @Override/*from   w  ww .  ja va2  s. c  o m*/
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            String gpsdata;
            switch (view.getId()) {
            case R.id.gpsfragment_sat_item_tv:
                gpsdata = (String) data;
                if (gpsdata.equals("TRUE")) {
                    view.setBackgroundResource(fixColorResource);
                } else if (gpsdata.equals("FALSE")) {
                    view.setBackgroundResource(stdColorResource);
                } else {
                    ((TextView) view).setText(gpsdata);
                }
                return true;
            default:
                return false;
            }
        }
    });
}

From source file:com.loadsensing.app.LlistaXarxesActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.xarxa_list_view);

    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    // adapter per mapejar els camps del layout amb la informaci de l'array
    SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.xarxa_row_list_view,
            new String[] { "nom", "poblacio", "sensors", "lat", "lon", "idXarxa", "nomThumbnail" },
            new int[] { R.id.text1, R.id.text2, R.id.text3, R.id.text4, R.id.text5, R.id.text6,
                    R.id.thumbnailxarxa });

    adapter.setViewBinder(new setImageListView());

    SharedPreferences settings = getSharedPreferences("LoadSensingApp", Context.MODE_PRIVATE);
    String address = SERVER_HOST + "?session=" + settings.getString("session", "");
    Log.d(DEB_TAG, "Requesting to " + address);

    try {/*from  w ww .  j  a  va 2s  . c o m*/
        String jsonString = JsonClient.connectString(address);

        // Convertim la resposta string a un JSONArray
        JSONArray llistaXarxesArray = new JSONArray(jsonString);

        HashMap<String, String> xarxa = null;

        // recorrer la llista de xarxes obtenint la informaci del JSON string
        for (int i = 0; i < llistaXarxesArray.length(); i++) {
            xarxa = new HashMap<String, String>();
            JSONObject xarxaJSON = new JSONObject();
            xarxaJSON = llistaXarxesArray.getJSONObject(i);
            // per mostrar la imatge de cada xarxa a la llista, fem una funci que ens retorna el nom de la imatge
            // segons quina id de xarxa es
            int nomImatge = obtenirNomImatge(xarxaJSON.getString("IdXarxa"));

            xarxa.put("id", String.valueOf(i));
            xarxa.put("poblacio", xarxaJSON.getString("Poblacio"));
            xarxa.put("nom", xarxaJSON.getString("Nom"));
            xarxa.put("idXarxa", xarxaJSON.getString("IdXarxa"));
            xarxa.put("sensors", xarxaJSON.getString("Sensors"));
            xarxa.put("lat", xarxaJSON.getString("Lat"));
            xarxa.put("lon", xarxaJSON.getString("Lon"));
            xarxa.put("nomThumbnail", Integer.toString(nomImatge));

            list.add(xarxa);
        }
        setListAdapter(adapter);

    } catch (Exception e) {
        Log.d(DEB_TAG, "Error rebent xarxes");
    }
}

From source file:org.ohmage.prompt.singlechoicecustom.SingleChoiceCustomPrompt.java

@Override
public View getView(final Context context) {

    mCustomChoices.clear();/*from   w w w  . j a va2s.c o  m*/
    SingleChoiceCustomDbAdapter dbAdapter = new SingleChoiceCustomDbAdapter(context);
    String surveyId = ((SurveyActivity) context).getSurveyId();
    SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
    String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
    String username = prefs.getUsername();
    if (dbAdapter.open()) {
        Cursor c = dbAdapter.getCustomChoices(username, campaignUrn, surveyId,
                SingleChoiceCustomPrompt.this.getId());
        c.moveToFirst();
        for (int i = 0; i < c.getCount(); i++) {
            //c.getLong(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_ID));
            int key = c.getInt(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_CHOICE_ID));
            String label = c.getString(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_CHOICE_VALUE));
            mCustomChoices.add(new KVLTriplet(String.valueOf(key), null, label));
            c.moveToNext();
        }
        c.close();
        dbAdapter.close();
    }

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //      mListView = (ListView) inflater.inflate(R.layout.prompt_single_choice_custom, null);
    mListView = new CustomChoiceListView(context);
    mListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mListView.setTextFilterEnabled(false);

    mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    mFooterView = inflater.inflate(R.layout.custom_choice_footer, null);

    EditText mEditText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
    ImageButton mButton = (ImageButton) mFooterView.findViewById(R.id.ok_button);
    ImageButton mCancelButton = (ImageButton) mFooterView.findViewById(R.id.cancel_button);

    showAddItemControls(context, mIsAddingNewItem);

    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (mEnteredText != null && !mEnteredText.equals("")) {
                SingleChoiceCustomDbAdapter dbAdapter = new SingleChoiceCustomDbAdapter(context);
                String surveyId = ((SurveyActivity) context).getSurveyId();
                SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
                String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
                String username = prefs.getUsername();

                int choiceId = 100;
                ArrayList<String> keys = new ArrayList<String>();
                for (KVLTriplet choice : mChoices) {
                    keys.add(choice.key.trim());
                }
                for (KVLTriplet choice : mCustomChoices) {
                    keys.add(choice.key.trim());
                }
                while (keys.contains(String.valueOf(choiceId))) {
                    choiceId++;
                }

                if (dbAdapter.open()) {
                    dbAdapter.addCustomChoice(choiceId, mEnteredText, username, campaignUrn, surveyId,
                            SingleChoiceCustomPrompt.this.getId());
                    dbAdapter.close();
                }

                showAddItemControls(context, false);

                mSelectedIndex = mListView.getCount() - 1;

                ((SurveyActivity) context).reloadCurrentPrompt();
            } else {
                Toast.makeText(context, "Please enter some text", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //            EditText edit = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            showAddItemControls(context, false);
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            mEnteredText = s.toString();
            //            mListView.setSelectionFromTop(mLastIndex, mLastTop);
            //            EditText editText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            //            editText.requestFocus();
        }
    });

    mListView.addFooterView(mFooterView);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);
    }
    for (int i = 0; i < mCustomChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mCustomChoices.get(i).key);
        map.put("value", mCustomChoices.get(i).label);
        data.add(map);
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.single_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    mListView.setAdapter(adapter);

    if (mSelectedIndex >= 0 && mSelectedIndex < mChoices.size() + mCustomChoices.size()) {
        mListView.setItemChecked(mSelectedIndex, true);
    }

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == mListView.getCount() - 1) {
                showAddItemControls(context, true);
                mSelectedIndex = -1;
                mLastIndex = mListView.getLastVisiblePosition();
                View v = mListView.getChildAt(mLastIndex);
                mLastTop = (v == null) ? 0 : v.getTop();
                mListView.setSelectionFromTop(mLastIndex, mLastTop);
            } else {
                //Map<String, String> map = (HashMap<String, String>) parent.getItemAtPosition(position);
                //mSelectedKey = map.get("key");
                mSelectedIndex = position;
                //((SurveyActivity)context).setResponse(index, id, value)
            }
        }
    });

    mListView.setSelectionFromTop(mLastIndex, mLastTop);

    return mListView;
}

From source file:org.ohmage.prompt.multichoicecustom.MultiChoiceCustomPrompt.java

@Override
public View getView(final Context context) {

    mCustomChoices.clear();//from w  ww  .  jav  a2s . c om
    MultiChoiceCustomDbAdapter dbAdapter = new MultiChoiceCustomDbAdapter(context);
    String surveyId = ((SurveyActivity) context).getSurveyId();
    SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
    String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
    String username = prefs.getUsername();
    if (dbAdapter.open()) {
        Cursor c = dbAdapter.getCustomChoices(username, campaignUrn, surveyId,
                MultiChoiceCustomPrompt.this.getId());
        c.moveToFirst();
        for (int i = 0; i < c.getCount(); i++) {
            //c.getLong(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_ID));
            int key = c.getInt(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_CHOICE_ID));
            String label = c.getString(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_CHOICE_VALUE));
            mCustomChoices.add(new KVLTriplet(String.valueOf(key), null, label));
            c.moveToNext();
        }
        c.close();
        dbAdapter.close();
    }

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //      mListView = (ListView) inflater.inflate(R.layout.prompt_single_choice_custom, null);
    mListView = new CustomChoiceListView(context);
    mListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mListView.setTextFilterEnabled(false);

    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    mFooterView = inflater.inflate(R.layout.custom_choice_footer, null);

    EditText mEditText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
    ImageButton mButton = (ImageButton) mFooterView.findViewById(R.id.ok_button);
    ImageButton mCancelButton = (ImageButton) mFooterView.findViewById(R.id.cancel_button);

    showAddItemControls(context, mIsAddingNewItem);

    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (mEnteredText != null && !mEnteredText.equals("")) {
                MultiChoiceCustomDbAdapter dbAdapter = new MultiChoiceCustomDbAdapter(context);
                String surveyId = ((SurveyActivity) context).getSurveyId();
                SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
                String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
                String username = prefs.getUsername();

                int choiceId = 100;
                ArrayList<String> keys = new ArrayList<String>();
                for (KVLTriplet choice : mChoices) {
                    keys.add(choice.key.trim());
                }
                for (KVLTriplet choice : mCustomChoices) {
                    keys.add(choice.key.trim());
                }
                while (keys.contains(String.valueOf(choiceId))) {
                    choiceId++;
                }

                if (dbAdapter.open()) {
                    dbAdapter.addCustomChoice(choiceId, mEnteredText, username, campaignUrn, surveyId,
                            MultiChoiceCustomPrompt.this.getId());
                    dbAdapter.close();
                }

                showAddItemControls(context, false);

                mSelectedIndexes.add(Integer.valueOf(mListView.getCount() - 1));

                ((SurveyActivity) context).reloadCurrentPrompt();
            } else {
                Toast.makeText(context, "Please enter some text", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //            EditText edit = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            showAddItemControls(context, false);
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            mEnteredText = s.toString();
            //            mListView.setSelectionFromTop(mLastIndex, mLastTop);
            //            EditText editText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            //            editText.requestFocus();
        }
    });

    mListView.addFooterView(mFooterView);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);
    }
    for (int i = 0; i < mCustomChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mCustomChoices.get(i).key);
        map.put("value", mCustomChoices.get(i).label);
        data.add(map);
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.multi_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    mListView.setAdapter(adapter);

    if (mSelectedIndexes.size() > 0) {
        for (int index : mSelectedIndexes) {
            if (index >= 0 && index < mChoices.size() + mCustomChoices.size())
                mListView.setItemChecked(index, true);
        }
    }

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == mListView.getCount() - 1) {
                showAddItemControls(context, true);
                mLastIndex = mListView.getLastVisiblePosition();
                View v = mListView.getChildAt(mLastIndex);
                mLastTop = (v == null) ? 0 : v.getTop();
                mListView.setSelectionFromTop(mLastIndex, mLastTop);
            } else {
                //SparseBooleanArray checkItemPositions = ((ListView)parent).getCheckedItemPositions();
                if (((ListView) parent).isItemChecked(position)) {
                    mSelectedIndexes.add(Integer.valueOf(position));
                } else {
                    mSelectedIndexes.remove(Integer.valueOf(position));
                }
            }
        }
    });

    mListView.setSelectionFromTop(mLastIndex, mLastTop);

    return mListView;
}

From source file:cm.aptoide.pt.RemoteInSearch.java

private void redraw() {

    apk_lst = db.getSearch(query, order_lst);

    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    Map<String, Object> apk_line;

    for (ApkNode node : apk_lst) {
        apk_line = new HashMap<String, Object>();
        if (node.status == 0) {
            apk_line.put("status", getString(R.string.not_inst));
            apk_line.put("name", node.name);
        } else if (node.status == 1) {
            apk_line.put("status", getString(R.string.installed) + " " + node.ver);
            apk_line.put("name", node.name);
        } else {//www  .j a  va 2s.  com
            apk_line.put("status2", getString(R.string.installed_update) + " " + node.ver);
            apk_line.put("name2", node.name);
        }
        String iconpath = new String(this.getString(R.string.icons_path) + node.apkid);
        apk_line.put("icon", iconpath);
        apk_line.put("rat", node.rat);
        result.add(apk_line);
    }
    SimpleAdapter show_out = new SimpleAdapter(this, result, R.layout.listicons,
            new String[] { "name", "name2", "status", "status2", "icon", "rat" },
            new int[] { R.id.name, R.id.nameup, R.id.isinst, R.id.isupdt, R.id.appicon, R.id.rating });
    show_out.setViewBinder(new RemoteInSearch.LstBinder());
    setListAdapter(show_out);
}

From source file:com.jefftharris.passwdsafe.FileListFragment.java

/** Update files after the loader is complete */
private void updateFiles(List<Map<String, Object>> fileData) {
    SimpleAdapter adapter = null;
    if (fileData != null) {
        adapter = new SimpleAdapter(getActivity(), fileData, R.layout.file_list_item,
                new String[] { TITLE, ICON, MOD_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date });
        adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
            @Override/*  w ww .  j ava  2 s.c  o  m*/
            public boolean setViewValue(View view, Object data, String textRepresentation) {
                switch (view.getId()) {
                case R.id.text: {
                    TextView tv = (TextView) view;
                    tv.setText(textRepresentation);
                    tv.requestLayout();
                    return true;
                }
                case R.id.mod_date: {
                    if (data == null) {
                        view.setVisibility(View.GONE);
                        return true;
                    } else {
                        view.setVisibility(View.VISIBLE);
                        return false;
                    }
                }
                }
                return false;
            }
        });
    }

    View rootView = getView();
    if (rootView == null) {
        // Fragment destroyed
        return;
    }
    View groupPanel = rootView.findViewById(R.id.current_group_panel);
    TextView groupLabel = (TextView) rootView.findViewById(R.id.current_group_label);
    TextView emptyLabel = (TextView) rootView.findViewById(android.R.id.empty);
    if (itsDir == null) {
        groupPanel.setVisibility(View.GONE);
        groupLabel.setText("");
        emptyLabel.setText(R.string.ext_storage_not_mounted);
    } else {
        groupPanel.setVisibility(View.VISIBLE);
        groupLabel.setText(itsDir.toString());
        emptyLabel.setText(R.string.no_files);
    }

    setListAdapter(adapter);

    // Open the default file
    if (getListAdapter() != null) {
        Activity act = getActivity();
        PasswdSafeApp app = (PasswdSafeApp) act.getApplication();
        if (app.checkOpenDefault()) {
            SharedPreferences prefs = Preferences.getSharedPrefs(act);
            Uri defFile = Preferences.getDefFilePref(prefs);
            if (defFile != null) {
                itsListener.openFile(defFile, null);
            }
        }
    }
}

From source file:net.tjado.passwdsafe.FileListFragment.java

/** Update files after the loader is complete */
private void updateFiles(List<Map<String, Object>> fileData) {
    SimpleAdapter adapter = null;
    if (fileData != null) {
        adapter = new SimpleAdapter(getActivity(), fileData, R.layout.file_list_item,
                new String[] { TITLE, ICON, MOD_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date });
        adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
            @Override/*from   w  w w .  jav a  2s.  c om*/
            public boolean setViewValue(View view, Object data, String textRepresentation) {
                switch (view.getId()) {
                case R.id.icon: {
                    ImageView iv = (ImageView) view;
                    iv.setImageResource((int) data);
                    iv.setColorFilter(getResources().getColor(R.color.treeview_icons));
                    return true;
                }
                case R.id.text: {
                    TextView tv = (TextView) view;
                    tv.setText(textRepresentation);
                    tv.requestLayout();
                    return true;
                }
                case R.id.mod_date: {
                    if (data == null) {
                        view.setVisibility(View.GONE);
                        return true;
                    } else {
                        view.setVisibility(View.VISIBLE);
                        return false;
                    }
                }
                }
                return false;
            }
        });
    }

    View rootView = getView();
    if (rootView == null) {
        // Fragment destroyed
        return;
    }
    View groupPanel = rootView.findViewById(R.id.current_group_panel);
    TextView groupLabel = (TextView) rootView.findViewById(R.id.current_group_label);
    TextView emptyLabel = (TextView) rootView.findViewById(android.R.id.empty);
    if (itsDir == null) {
        groupPanel.setVisibility(View.GONE);
        groupLabel.setText("");
        emptyLabel.setText(R.string.ext_storage_not_mounted);
    } else {
        groupPanel.setVisibility(View.VISIBLE);
        groupLabel.setText(itsDir.toString());
        emptyLabel.setText(R.string.no_files);
    }

    setListAdapter(adapter);

    // Open the default file
    if (getListAdapter() != null) {
        Activity act = getActivity();
        PasswdSafeApp app = (PasswdSafeApp) act.getApplication();
        if (app.checkOpenDefault()) {
            SharedPreferences prefs = Preferences.getSharedPrefs(act);
            Uri defFile = Preferences.getDefFilePref(prefs);
            if (defFile != null) {
                itsListener.openFile(defFile, null);
            }
        }
    }
}