Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

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

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.ame.armymax.SearchActivity.java

public void newSearchResultCb(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (jo != null) {
        resultList.clear();/*  ww  w . ja  va2 s. c  o  m*/
        JSONObject people = jo.getJSONObject("people");

        JSONArray ja = people.getJSONArray("data");

        for (int i = 0; i < ja.length(); i++) {
            JSONObject post = ja.getJSONObject(i);

            String name = post.getString("UserFirstName") + " " + post.getString("UserLastName");
            String userName = post.getString("UserName");

            String avatar = post.getString("UserAvatarPath");
            Integer userId = Integer.parseInt(post.getString("UserID"));

            if (!avatar.contains("facebook"))
                avatar = Data.BASE + avatar + "/thumbnail_500";
            //avatar = "http://www.armymax.com/photo/" + avatar;

            DataSearchResult result = new DataSearchResult(userId, name, userName, avatar);

            resultList.add(result);
        }

        new AdapterHelper().update((ArrayAdapter<DataSearchResult>) adapter, new ArrayList<Object>(resultList));
        ListUtil.setListViewHeightBasedOnChildren(listView);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

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

                DataSearchResult p = (DataSearchResult) parentAdapter.getItemAtPosition(position);

                intent.putExtra("id", p.getUserId().toString());
                intent.putExtra("username", p.getUserName());
                startActivity(intent);

            }
        });

        // we register for the contextmneu
        registerForContextMenu(listView);

    }
}

From source file:com.ame.armymax.SearchActivity.java

public void searchResultCb(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (jo != null) {
        resultList.clear();//from   w w w. ja  v a  2  s.c  om
        JSONObject people = jo.getJSONObject("people");

        JSONArray ja = people.getJSONArray("data");

        for (int i = 0; i < ja.length(); i++) {
            JSONObject post = ja.getJSONObject(i);

            String name = post.getString("UserFirstName") + " " + post.getString("UserLastName");
            String userName = post.getString("UserName");

            String avatar = post.getString("UserAvatarPath");
            Integer userId = Integer.parseInt(post.getString("UserID"));

            if (!avatar.contains("facebook"))
                avatar = Data.BASE + avatar + "/thumbnail_500";

            DataSearchResult result = new DataSearchResult(userId, name, userName, avatar);

            resultList.add(result);
        }

    }

    listView = (ListView) findViewById(R.id.listView);
    adapter = new SearchResultAdapter(resultList, this);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

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

            DataSearchResult p = (DataSearchResult) parentAdapter.getItemAtPosition(position);

            intent.putExtra("id", p.getUserId().toString());
            intent.putExtra("username", p.getUserName());
            startActivity(intent);

        }
    });

    // we register for the contextmneu
    registerForContextMenu(listView);

    // TextFilter
    //listView.setTextFilterEnabled(true);

}

From source file:in.dasilvacont.hearthstonecards.app.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The CardAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    String sortOrder = CardContract.CardEntry.COLUMN_CARD_NAME + " ASC";
    Cursor cur = getActivity().getContentResolver().query(CardContract.CardEntry.CONTENT_URI, null, null, null,
            sortOrder);// w w  w . j  a  va2s  .  c o m

    if (cur.getCount() == 0)
        fetchCards();

    mCardAdapter = new CardAdapter(getActivity(), cur, 0);

    Log.d(LOG_TAG, "Inflating CardFragment...");
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_card);
    mListView.setAdapter(mCardAdapter);

    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                /*
                ((Callback) getActivity())
                    .onItemSelected(CardContract.CardEntry.buildCardUri(
                            cursor.getString(COL_CARD_ID)
                    ));
                    */
                Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                        CardContract.CardEntry.buildCardUriNumerical(cursor.getLong(COL_ID)));
                startActivity(intent);
            }
            mPosition = position;

        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
        mListView.smoothScrollToPosition(mPosition);
        mListView.setSelection(mPosition);
    }

    return rootView;
}

From source file:com.example.moneymeterexample.AddExpenseActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub

    String category_val = parent.getItemAtPosition(position).toString();
    if (category_val.equals("New...")) {

        showDialog(NEW_CATEGORY_ID);//  w w w .j av a  2  s . co  m

    }
}

From source file:org.droid2droid.ui.contacts.AbstractSMSFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mMain = inflater.inflate(R.layout.expose_sms, container, false);

    mUsage = (TextView) mMain.findViewById(R.id.usage);

    mEditText = (EditText) mMain.findViewById(R.id.numberEditText);
    mEditText.addTextChangedListener(this);
    mEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override//from   w w  w .  java  2 s  . c  om
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                final String receiver = mEditText.getText().toString();
                if (mSendedData != null || receiver != null)
                    if (receiver.matches("[0123456789#*()\\- ]*"))
                        sendData(receiver);
                return true;
            }
            return false;
        }
    });

    mList = (ListView) mMain.findViewById(android.R.id.list);
    mList.setOnScrollListener(this);
    mList.setFastScrollEnabled(true);
    mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg3) {
            final long id = ((Cursor) adapter.getItemAtPosition(position)).getLong(POS_ID);
            if (id > 0) {
                RAApplication.hideSoftKeyboard(getActivity());
                final PhoneDisambigDialog phoneDialog = new PhoneDisambigDialog(getActivity(),
                        AbstractSMSFragment.this, id);
                phoneDialog.show();
            }
        }
    });
    return mMain;
}

From source file:com.ffmpegtest.VideoActivity.java

@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
    Cursor c = (Cursor) parentView.getItemAtPosition(position);
    if (parentView == mLanguageSpinner) {
        if (mLanguageSpinnerSelectedPosition != position) {
            mLanguageSpinnerSelectedPosition = position;
            mAudioStreamNo = c.getInt(PROJECTION_ID);
            setDataSourceAndResumeState();
        }//from  w w w  .ja v  a 2  s. c om
    } else if (parentView == mSubtitleSpinner) {
        if (mSubtitleSpinnerSelectedPosition != position) {
            mSubtitleSpinnerSelectedPosition = position;
            mSubtitleStreamNo = c.getInt(PROJECTION_ID);
            setDataSourceAndResumeState();
        }
    } else {
        throw new RuntimeException();
    }
}

From source file:com.vuze.android.remote.activity.IntentHandler.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "OnCreate");
    }/*w w  w .  j a v a  2s . c o  m*/
    AndroidUtilsUI.onCreate(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intent_handler);

    final Intent intent = getIntent();

    if (handleIntent(intent, savedInstanceState)) {
        return;
    }

    listview = (ListView) findViewById(R.id.lvRemotes);
    assert listview != null;
    listview.setItemsCanFocus(false);

    adapter = new ProfileArrayAdapter(this);

    listview.setAdapter(adapter);

    if (AndroidUtils.DEBUG) {
        Log.d("TUX1", "DS: " + intent.getDataString());
    }

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            Object item = parent.getItemAtPosition(position);

            if (item instanceof RemoteProfile) {
                RemoteProfile remote = (RemoteProfile) item;
                new RemoteUtils(IntentHandler.this).openRemote(remote,
                        IntentHandler.this.getIntent().getData() != null);
            }
        }

    });

    Toolbar toolBar = (Toolbar) findViewById(R.id.actionbar);
    if (toolBar != null) {
        setSupportActionBar(toolBar);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setIcon(R.drawable.ic_launcher);
    }

    registerForContextMenu(listview);
}

From source file:com.craftloom.android.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mForecastAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*w  w  w.  java 2  s  . c  o m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }
    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
    return rootView;
}

From source file:com.example.android.spotifystreamer.app.spotifystreamerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The spotifystreamerAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mspotifystreamerAdapter = new spotifystreamerAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mspotifystreamerAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*from   w w w. jav  a  2  s  .c o  m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mspotifystreamerAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.normalexception.app.rx8club.fragment.pm.PrivateMessageInboxFragment.java

private void updateList() {
    final Fragment _frag = this;
    getActivity().runOnUiThread(new Runnable() {
        public void run() {
            pmva = new PMViewArrayAdapter(_frag, R.layout.view_pm, pmlist);
            lv.setAdapter(pmva);//w  w w .j a  v  a  2  s . co m
            lv.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    PMModel pm = (PMModel) parent.getItemAtPosition(position);

                    Bundle args = new Bundle();
                    args.putString("link", pm.getLink());

                    // Create new fragment and transaction
                    Fragment newFragment = new PrivateMessageViewFragment();
                    newFragment.setArguments(args);
                    FragmentTransaction transaction = getFragmentManager().beginTransaction();

                    // Replace whatever is in the fragment_container view with this fragment,
                    // and add the transaction to the back stack
                    transaction.add(R.id.content_frame, newFragment);
                    transaction.addToBackStack(null);

                    // Commit the transaction
                    transaction.commit();
                }
            });
            registerForContextMenu(lv);
        }
    });
}