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.roamprocess1.roaming4world.ui.messages.ConversationsListFragment.java

public void onVisibilityChanged_custom(boolean visible) {

    deleteRegistrarAck();/*from  www  . java 2  s . c o m*/

    if (visible) {
        attachAdapter();
        // 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.roamprocess1.roaming4world.ui.messages.ConversationsListFragment.java

@Override
public void onVisibilityChanged(boolean visible) {

    deleteRegistrarAck();/* ww  w .ja v a  2  s .co m*/

    if (visible) {
        attachAdapter();
        // 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.roamprocess1.roaming4world.ui.calllog.CallLogListFragment.java

@SuppressLint("NewApi")
@Override/*from   w ww. j  a  v a2  s  .com*/
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.

        System.out.println("CallLogListFragment Step 10");
        SherlockFragmentActivity activity = getSherlockActivity();
        if (activity != null) {

            System.out.println("CallLogListFragment Step 11");
            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:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public void onDismiss(DialogInterface dialog) {
    ListView list = ((AlertDialog) dialog).getListView();
    int which = list.getCheckedItemPosition();

    CheckBox reverseSort = (CheckBox) list.findViewById(R.id.reverse_sort);
    if (reverseSort.isChecked()) {
        which = ~which;//from   www .  j  a va2 s . c om
    }

    mPagerAdapter.setSortMode(which);
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

@Override
public void onDismiss(DialogInterface dialog) {
    ListView list = ((AlertDialog) dialog).getListView();
    // subtract 1 for header
    int which = list.getCheckedItemPosition() - 1;

    CheckBox reverseSort = (CheckBox) list.findViewById(R.id.reverse_sort);
    if (reverseSort.isChecked()) {
        which = ~which;//from   w ww  .  ja v a 2s . c om
    }

    mPagerAdapter.setSortMode(which);
}

From source file:com.listomate.activities.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from w ww .j  ava  2  s.c o m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Register in the background and terminate the activity
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                register((String) account.getText());
                finish();
            }
        });

        final Button exitButton = (Button) findViewById(R.id.exit);
        exitButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
    }
}

From source file:com.simas.vc.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    ListView lv = mNavDrawerFragment.getListView();

    if (position == ListView.INVALID_POSITION || position < lv.getHeaderViewsCount()
            || position >= lv.getCount() - lv.getFooterViewsCount()) {
        // Skip headers and footers
        //noinspection UnnecessaryReturnStatement
        return;/*from   ww w .  j  ava2s  .co m*/
    } else {
        // Check the item in the drawer
        lv.setItemChecked(position, true);

        Object checkedItem = lv.getItemAtPosition(lv.getCheckedItemPosition());
        // Make sure the item is not already selected in the current EditorFragment
        if (lv.getChoiceMode() == ListView.CHOICE_MODE_SINGLE && getEditorFragment() != null
                && getEditorFragment().getItem() != checkedItem) {
            // Select item in pager
            int itemPosInPager = position - lv.getHeaderViewsCount() + 1; // +1 for empty item
            mViewPager.setCurrentItem(itemPosInPager);

            // Close drawer
            mNavDrawerFragment.setDrawerOpen(false);
        }
    }
}

From source file:com.myandroidremote.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 */// ww  w  .j a v  a 2s.  c om
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                showLoadingScreen();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Register in the background and terminate the activity
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                register((String) account.getText());

                // show connecting
                showLoadingScreen();
            }
        });

        final Button exitButton = (Button) findViewById(R.id.exit);
        exitButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
    }
}

From source file:com.cloudtask1.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from w  ww .j  av  a  2s  . c  o m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:nz.ac.wintec.soit.af5.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from   w w  w  . j  ava2 s  . c  o  m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //  startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}