Example usage for android.widget SimpleAdapter SimpleAdapter

List of usage examples for android.widget SimpleAdapter SimpleAdapter

Introduction

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

Prototype

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource,
        String[] from, @IdRes int[] to) 

Source Link

Document

Constructor

Usage

From source file:com.zprogrammer.tool.ui.NavigationDrawerFragment.java

private ListAdapter getAdapter() {
    ArrayList<Map<String, Object>> maps = new ArrayList<>();

    Map<String, Object> map0 = new HashMap<>();
    map0.put("icon", R.drawable.ic_item_drawer_main_home);
    map0.put("title", getString(R.string.title_main));
    maps.add(map0);/*from   ww w. j  a va2 s.  c om*/

    Map<String, Object> map1 = new HashMap<>();
    map1.put("icon", R.drawable.ic_item_drawer_main_favorites);
    map1.put("title", getString(R.string.title_favorites));
    maps.add(map1);

    Map<String, Object> map2 = new HashMap<>();
    map2.put("icon", R.drawable.ic_item_drawer_main_settings);
    map2.put("title", getString(R.string.title_settings));
    maps.add(map2);

    return new SimpleAdapter(getActivity(), maps, R.layout.item_list_drawer_main,
            new String[] { "icon", "title" }, new int[] { R.id.drawer_icon, R.id.drawer_title });
}

From source file:se.anyro.tagtider.TransferActivity.java

private void addChangesAdapter() {
    sChangesAdapter = new SimpleAdapter(this, sChanges, R.layout.change_row, FROM, TO);
    sChangesAdapter.setViewBinder(new ViewBinder() {
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            // Hide views with empty text
            if (textRepresentation.length() == 0) {
                view.setVisibility(View.GONE);
                return true;
            }/*from ww w  .  java  2  s. c o  m*/
            view.setVisibility(View.VISIBLE);

            return false;
        }
    });
    setListAdapter(sChangesAdapter);
}

From source file:ru.moscow.tuzlukov.sergey.weatherlog.SettingsActivity.java

private SimpleAdapter makeAdapter() {
    List<Map<String, String>> list = new ArrayList<>();
    Map<String, String> map;
    for (City city : cityList) {
        map = new HashMap<>();
        map.put("Fullname", String.format("%1$s [%2$s]", city.getName(), city.getCountry()));
        map.put("Info",
                String.format("lat=%1$.6f; lon=%2$.6f\nid=%3$d", city.getLat(), city.getLon(), city.getId()));
        list.add(map);/*from  w w  w  .ja  v a2s  .  c o  m*/
    }
    return new SimpleAdapter(this, list, android.R.layout.simple_list_item_2,
            new String[] { "Fullname", "Info" }, new int[] { android.R.id.text1, android.R.id.text2 });
}

From source file:net.reichholf.dreamdroid.fragment.ServiceListFragment.java

/**
 *
 *///from  w ww .  jav  a  2s  . c  om
private void setAdapter() {
    ListAdapter adapter;
    if (!mNavList.equals(mDetailList)) {
        adapter = new SimpleAdapter(getActionBarActivity(), mNavItems, android.R.layout.simple_list_item_1,
                new String[] { Event.KEY_SERVICE_NAME }, new int[] { android.R.id.text1 });
        mNavList.setAdapter(adapter);
    }
    adapter = new ServiceListAdapter(getActionBarActivity(), mDetailItems);
    if (Build.VERSION.SDK_INT < 11) {
        ((ListView) mDetailList).setAdapter(adapter);
    } else {
        mDetailList.setAdapter(adapter);
    }
}

From source file:fm.feed.android.SampleApp.fragment.TestFragment.java

private void updateStations(List<Station> stationList) {
    List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
    for (Station s : stationList) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("Id", s.getId() + "");
        map.put("Station", s.getName());
        fillMaps.add(map);/*from w w  w .j a v a  2 s  . c  o  m*/
    }

    final SimpleAdapter adapter = new SimpleAdapter(getActivity(), fillMaps, R.layout.list_item,
            new String[] { "Id", "Station" }, new int[] { R.id.id, R.id.name });
    mStationsView.setAdapter(adapter);
    mStationsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mSelectedStationIndex = position;

            HashMap<String, Integer> item = (HashMap<String, Integer>) adapter.getItem(position);
            Integer stationId = Integer.parseInt(String.valueOf(item.get("Id")));
            mPlayer.setStationId(stationId);
        }
    });
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

public final void popupGetStatus(JSONArray pStatusesArray) {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;
    final int height = dm.heightPixels;

    int popupWidth = (int) (width * 0.75);
    int popupHeight = height;

    // Inflate the popup_layout.xml
    ScrollView viewGroup = (ScrollView) this.activity.findViewById(R.id.popupGetStatus);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_get_status, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupPublishStatus = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupPublishStatus.setBackgroundDrawable(new BitmapDrawable());
    popupPublishStatus.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupPublishStatus.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }/* ww  w . ja v a 2  s .c o  m*/
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Find the ListView resource. 
    ListView mainListView = (ListView) layout.findViewById(R.id.listViewStatus);

    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    SimpleAdapter adapter = new SimpleAdapter(this.activity, list, R.layout.custom_row_view,
            new String[] { "content", "lat", "lon" }, new int[] { R.id.text1, R.id.text2, R.id.text3 });

    try {
        // Appel REST pour recuperer les status de l'utilisateur connect
        //Session session = new Session(this.activity);
        //session.parseJSONUrl("https://jibiki.univ-savoie.fr/ltpdev/rest.php/api/1/statuses", "STATUSES", "GET");

        // Parser la liste des amis dans le OverlayItem ArrayList
        HashMap<String, String> temp;
        for (int i = 0; (i < 6); i++) {
            // Obtenir le status
            JSONObject status = pStatusesArray.getJSONObject(i);

            temp = new HashMap<String, String>();
            temp.put("content", status.getString("content"));
            temp.put("lat", String.valueOf(status.getDouble("lat")));
            temp.put("lon", String.valueOf(status.getDouble("lon")));
            list.add(temp);
        }
    } catch (JSONException jex) {
        Log.e("Catch", "popupGetStatus / JSONException : " + jex.getStackTrace());
    } catch (Exception ex) {
        Log.e("Catch", "popupGetStatus / Exception : " + ex.getLocalizedMessage());
    }

    mainListView.setAdapter(adapter);
}

From source file:eu.geekgasm.kintrol.DeviceControlActivity.java

ListAdapter createDeviceInfoListAdapter() {
    final String[] fromMapKey = new String[] { "key", "value" };
    final int[] toLayoutId = new int[] { android.R.id.text1, android.R.id.text2 };
    final List<Map<String, String>> list = new ArrayList<>();
    list.add(createListEntry("Device Name", deviceInfo.deviceName));
    list.add(createListEntry("IP Address", deviceInfo.ipAddress));
    list.add(createListEntry("Device ID", deviceId != null ? deviceId : "unknown"));
    list.add(createListEntry("Total Operation Time", renderOperationTime(powerCounterValue)));
    addSoftwareVersions(list);/* www .j  a v a 2 s.c  o  m*/

    return new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, fromMapKey, toLayoutId);
}

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 {//from   w ww .  j  av  a 2 s  . c o m
            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.abeo.tia.noordin.ProcessCaseVendor.java

public void dropdownKIV() throws JSONException {
    RequestParams params = null;/*ww  w . java2  s. com*/
    params = new RequestParams();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("TableName", "OCRD");
    jsonObject.put("FieldName", "KIVSTATUS");
    params.put("sJsonInput", jsonObject.toString());

    RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("Failed");

        }

        @Override
        protected String parseResponse(String s, boolean b) throws Throwable {
            return null;
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Title Dropdown Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonArraylist = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    id = jsonResponse.getString("Id").toString();
                    name = jsonResponse.getString("Name").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> proList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON  LIST");
                    proList.put("Id_T", id);
                    System.out.println(name);
                    proList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON PROPERTY LIST");

                    jsonArraylist.add(proList);
                    System.out.println("JSON PROPERTY LIST");
                    System.out.println(jsonArraylist);
                }
                // Spinner set Array Data in Drop down

                sAdapPROJ = new SimpleAdapter(ProcessCaseVendor.this, jsonArraylist, R.layout.spinner_item,
                        new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name });

                spinner_kiv.setAdapter(sAdapPROJ);

                for (int j = 0; j < jsonArraylist.size(); j++) {
                    if (jsonArraylist.get(j).get("Id_T").equals(Skiv)) {
                        spinner_kiv.setSelection(j);
                        break;
                    }
                }

            } catch (JSONException e) {

                e.printStackTrace();
            }
        }
    });
}