Example usage for android.widget SimpleAdapter getItem

List of usage examples for android.widget SimpleAdapter getItem

Introduction

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

Prototype

public Object getItem(int position) 

Source Link

Usage

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 ava 2 s.  co  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:fm.feed.android.testapp.fragment.TestFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mBtnTune.setOnClickListener(tune);/*from   www.ja  v a 2 s.  c om*/
    mBtnPlay.setOnClickListener(play);
    mBtnPause.setOnClickListener(pause);
    mBtnSkip.setOnClickListener(skip);
    mBtnLike.setOnClickListener(like);
    mBtnUnlike.setOnClickListener(unlike);
    mBtnDislike.setOnClickListener(dislike);
    mBtnHistory.setOnClickListener(history);

    mPlacementsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mStationsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    mBtnToggleWifi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ConnectivityManager cm = (ConnectivityManager) getActivity()
                    .getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

            WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
            wifi.setWifiEnabled(!isConnected); // true or false to activate/deactivate wifi

            mBtnToggleWifi.setText(!isConnected ? "Wifi ON" : "Wifi OFF");
        }
    });

    List<HashMap<String, Integer>> fillMaps = new ArrayList<HashMap<String, Integer>>();
    for (Integer p : mPlacements) {
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        map.put("Placement", p);
        fillMaps.add(map);
    }

    final SimpleAdapter adapter = new SimpleAdapter(getActivity(), fillMaps,
            android.R.layout.simple_list_item_1, new String[] { "Placement" },
            new int[] { android.R.id.text1 });
    mPlacementsView.setAdapter(adapter);
    mPlacementsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mSelectedPlacementsIndex = position;

            HashMap<String, Integer> item = (HashMap<String, Integer>) adapter.getItem(position);
            Integer placementId = item.get("Placement");
            Toast.makeText(getActivity(), placementId.toString(), Toast.LENGTH_LONG).show();
            mPlayer.setPlacementId(placementId);

        }
    });

    resetTrackInfo();

    if (mPlayer.hasPlay()) {
        updateTrackInfo(mPlayer.getPlay());
    }
    if (mPlayer.hasStationList()) {
        updateStations(mPlayer.getStationList());
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void showSmileyDialog() {
    if (mSmileyDialog == null) {
        int[] icons = SmileyParser.DEFAULT_SMILEY_RES_IDS;
        String[] names = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_NAMES);
        final String[] texts = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_TEXTS);

        final int N = names.length;

        List<Map<String, ?>> entries = new ArrayList<Map<String, ?>>();
        for (int i = 0; i < N; i++) {
            // We might have different ASCII for the same icon, skip it if
            // the icon is already added.
            boolean added = false;
            for (int j = 0; j < i; j++) {
                if (icons[i] == icons[j]) {
                    added = true;//from  w ww.j a  v  a  2s .  c o  m
                    break;
                }
            }
            if (!added) {
                HashMap<String, Object> entry = new HashMap<String, Object>();

                entry.put("icon", icons[i]);
                entry.put("name", names[i]);
                entry.put("text", texts[i]);

                entries.add(entry);
            }
        }

        final SimpleAdapter a = new SimpleAdapter(this, entries, R.layout.smiley_menu_item,
                new String[] { "icon", "name", "text" },
                new int[] { R.id.smiley_icon, R.id.smiley_name, R.id.smiley_text });
        SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Object data, String textRepresentation) {
                if (view instanceof ImageView) {
                    Drawable img = getResources().getDrawable((Integer) data);
                    ((ImageView) view).setImageDrawable(img);
                    return true;
                }
                return false;
            }
        };
        a.setViewBinder(viewBinder);

        AlertDialog.Builder b = new AlertDialog.Builder(this);

        b.setTitle(getString(R.string.menu_insert_smiley));

        b.setCancelable(true);
        b.setAdapter(a, new DialogInterface.OnClickListener() {
            @Override
            @SuppressWarnings("unchecked")
            public final void onClick(DialogInterface dialog, int which) {
                HashMap<String, Object> item = (HashMap<String, Object>) a.getItem(which);

                String smiley = (String) item.get("text");
                if (mSubjectTextEditor != null && mSubjectTextEditor.hasFocus()) {
                    mSubjectTextEditor.append(smiley);
                } else {
                    mTextEditor.append(smiley);
                }

                dialog.dismiss();
            }
        });

        mSmileyDialog = b.create();
    }

    mSmileyDialog.show();
}