Example usage for android.widget ListView getCheckedItemPosition

List of usage examples for android.widget ListView getCheckedItemPosition

Introduction

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

Prototype

public int getCheckedItemPosition() 

Source Link

Document

Returns the currently checked item.

Usage

From source file:com.friedran.appengine.dashboard.gui.DashboardActivity.java

private static String getNavigationListCheckedItem(ListView listView) {
    int checkedPosition = listView.getCheckedItemPosition();
    if (checkedPosition == ListView.INVALID_POSITION)
        return null;

    return (String) listView.getItemAtPosition(checkedPosition);
}

From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java

private void onSingleChoiceItemClick(ListView listView, SingleChoiceQuestion question) {
    int i = listView.getCheckedItemPosition();
    if (i != ListView.INVALID_POSITION) {
        question.saveAnswer(i);//from w  w  w .  j a  v  a2 s  .c o m
    }
}

From source file:aws.apps.usbDeviceEnumerator.ui.main.MainActivity.java

private void onTabChanged(String tabId, TabViewHolder tabViewHolder) {
    if (mNavigation.isSmallScreen()) {
        return;//from   w ww  . j  a va2s  .co m
    }

    final ListView listView = tabViewHolder.getList();
    final int checkedItemPosition = listView.getCheckedItemPosition();
    final Fragment fragment;

    if (checkedItemPosition == ListView.INVALID_POSITION) {
        fragment = null;
    } else {
        final String text = (String) listView.getItemAtPosition(checkedItemPosition);

        switch (tabId) {
        case TabController.TAB_ANDROID_INFO:
            fragment = InfoFragmentFactory.getFragment(text);
            break;
        case TabController.TAB_LINUX_INFO:
            fragment = InfoFragmentFactory.getFragment(mLinuxDeviceMap.get(text));
            break;
        default:
            fragment = null;
            break;
        }
    }

    if (fragment == null) {
        mNavigation.removeFragmentsFromContainer();
    } else {
        mNavigation.stackFragment(fragment);
    }
}

From source file:com.abcvoipsip.ui.calllog.CallLogListFragment.java

@Override
public void onVisibilityChanged(boolean visible) {
    if (mShowOptionsMenu != visible) {
        mShowOptionsMenu = visible;/* w  w w  . j  av a 2s. c  o  m*/
        // Invalidate the options menu since we are changing the list of
        // options shown in it.
        SupportActivity activity = getSupportActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
        }
    }
    if (visible && isResumed()) {
        getLoaderManager().restartLoader(0, null, this);
        ListView lv = getListView();
        if (lv != null && mAdapter != null) {
            final int checkedPos = lv.getCheckedItemPosition();
            if (checkedPos >= 0) {
                // TODO post instead
                Thread t = new Thread() {
                    public void run() {
                        final long[] selectedIds = mAdapter.getCallIdsAtPosition(checkedPos);
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                viewDetails(checkedPos, selectedIds);
                            }
                        });
                    };
                };
                t.start();
            }
        }
    }
}

From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = getListView();
    int choiceMode = list.getChoiceMode();
    mLastChoiceMode = choiceMode;//from   w  ww .ja va 2 s . com
    if (choiceMode == ListView.CHOICE_MODE_SINGLE)
        mLastCheckedItem = list.getCheckedItemPosition();
    else
        mLastCheckedItem = ListView.INVALID_POSITION;
    if (Build.VERSION.SDK_INT < 11) {
        list.setItemChecked(mLastCheckedItem, false);

        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setLongClickable(false);
        ((ActionBarActivity) getActivity()).startSupportActionMode(new InternalOlderListener());
        if (mListener != null)
            mListener.onItemCheckedStateChanged(mWrapper, position, id, true);
    } else {
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    }
    list.setItemChecked(position, true);
    return true;
}

From source file:com.akalipetis.fragment.ActionModeListFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = getListView();
    int choiceMode = list.getChoiceMode();
    mLastChoiceMode = choiceMode;/*from  ww  w  . j  a  v a  2  s  .c  o m*/
    if (choiceMode == ListView.CHOICE_MODE_SINGLE)
        mLastCheckedItem = list.getCheckedItemPosition();
    else
        mLastCheckedItem = ListView.INVALID_POSITION;
    if (Build.VERSION.SDK_INT < 11) {
        list.setItemChecked(mLastCheckedItem, false);

        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        list.setLongClickable(false);
        ((AppCompatActivity) getActivity()).startSupportActionMode(new InternalOlderListener());
        list.setItemChecked(position, true);
        if (mListener != null)
            mListener.onItemCheckedStateChanged(mWrapper, position, id, true);
    } else {
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        list.setItemChecked(position, true);
    }
    return true;
}

From source file:com.abcvoipsip.ui.messages.ConversationsListFragment.java

@Override
public void onVisibilityChanged(boolean visible) {

    if (visible && isResumed()) {
        getLoaderManager().restartLoader(0, null, this);
        //}/*  ww w  .j  a  va2s.  com*/
        //if (visible) {
        ListView lv = getListView();
        if (lv != null && mAdapter != null) {
            final int checkedPos = lv.getCheckedItemPosition();
            if (checkedPos >= 0) {
                // TODO post instead
                Thread t = new Thread() {
                    public void run() {
                        // -1 because of the new message row
                        Cursor c = (Cursor) mAdapter.getItem(checkedPos - 1);
                        if (c != null) {
                            String from = c.getString(c.getColumnIndex(SipMessage.FIELD_FROM));
                            String to = c.getString(c.getColumnIndex(SipMessage.FIELD_TO));
                            final String fromFull = c.getString(c.getColumnIndex(SipMessage.FIELD_FROM_FULL));
                            String number = from;
                            if (SipMessage.SELF.equals(number)) {
                                number = to;
                            }
                            final String nbr = number;
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    viewDetails(checkedPos, nbr, fromFull);
                                }
                            });
                        }
                    };
                };
                t.start();
            }
        }
    }
}

From source file:com.csipsimple.ui.messages.ConversationsListFragment.java

@Override
public void onVisibilityChanged(boolean visible) {

    if (visible) {
        attachAdapter();/*from  w  w  w  . j  av a2s  .  c om*/
        // Start loading
        if (!alreadyLoaded) {
            getLoaderManager().initLoader(0, null, this);
            alreadyLoaded = true;
        }
    }

    if (visible && isResumed()) {
        ListView lv = getListView();
        if (lv != null && mAdapter != null) {
            final int checkedPos = lv.getCheckedItemPosition();
            if (checkedPos >= 0) {
                // TODO post instead
                Thread t = new Thread() {
                    public void run() {
                        Cursor c = (Cursor) mAdapter.getItem(checkedPos - getListView().getHeaderViewsCount());
                        if (c != null) {
                            String from = c.getString(c.getColumnIndex(SipMessage.FIELD_FROM));
                            String to = c.getString(c.getColumnIndex(SipMessage.FIELD_TO));
                            final String fromFull = c.getString(c.getColumnIndex(SipMessage.FIELD_FROM_FULL));
                            String number = from;
                            if (SipMessage.SELF.equals(number)) {
                                number = to;
                            }
                            final String nbr = number;
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    viewDetails(checkedPos, nbr, fromFull);
                                }
                            });
                        }
                    };
                };
                t.start();
            }
        }
    }
}

From source file:com.fututel.ui.calllog.CallLogListFragment.java

@Override
public void onVisibilityChanged(boolean visible) {
    if (mShowOptionsMenu != visible) {
        mShowOptionsMenu = visible;/*from ww  w  . j  av  a 2  s.  co  m*/
        // Invalidate the options menu since we are changing the list of
        // options shown in it.
        SherlockFragmentActivity activity = getSherlockActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
        }
    }

    if (visible) {
        attachAdapter();
        // Start loading
        if (!alreadyLoaded) {
            getLoaderManager().initLoader(0, null, this);
            alreadyLoaded = true;
        }
    }

    if (visible && isResumed()) {
        //getLoaderManager().restartLoader(0, null, this);
        ListView lv = getListView();
        if (lv != null && mAdapter != null) {
            final int checkedPos = lv.getCheckedItemPosition();
            if (checkedPos >= 0) {
                // TODO post instead
                Thread t = new Thread() {
                    public void run() {
                        final long[] selectedIds = mAdapter.getCallIdsAtPosition(checkedPos);
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                viewDetails(checkedPos, selectedIds);
                            }
                        });
                    };
                };
                t.start();
            }
        }
    }

    if (!visible && mMode != null) {
        mMode.finish();
    }
}

From source file:com.csipsimple.ui.calllog.CallLogListFragment.java

@SuppressLint("NewApi")
@Override/*from   ww w.ja va  2 s. c o  m*/
public void onVisibilityChanged(boolean visible) {
    if (mShowOptionsMenu != visible) {
        mShowOptionsMenu = visible;
        // Invalidate the options menu since we are changing the list of
        // options shown in it.
        SherlockFragmentActivity activity = getSherlockActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
        }
    }

    if (visible) {
        attachAdapter();
        // Start loading
        if (!alreadyLoaded) {
            getLoaderManager().initLoader(0, null, this);
            alreadyLoaded = true;
        }
    }

    if (visible && isResumed()) {
        //getLoaderManager().restartLoader(0, null, this);
        ListView lv = getListView();
        if (lv != null && mAdapter != null) {
            final int checkedPos = lv.getCheckedItemPosition();
            if (checkedPos >= 0) {
                // TODO post instead
                Thread t = new Thread() {
                    public void run() {
                        final long[] selectedIds = mAdapter.getCallIdsAtPosition(checkedPos);
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                viewDetails(checkedPos, selectedIds);
                            }
                        });
                    };
                };
                t.start();
            }
        }
    }

    if (!visible && mMode != null) {
        mMode.finish();
    }
}