Example usage for android.widget ListView setItemChecked

List of usage examples for android.widget ListView setItemChecked

Introduction

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

Prototype

public void setItemChecked(int position, boolean value) 

Source Link

Document

Sets the checked state of the specified position.

Usage

From source file:com.masteriti.manager.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*w  ww  .  j  av  a2  s .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() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            @Override
            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() {
            @Override
            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:id.ridon.keude.views.fragments.SelectLocalAppsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
    adapter.swapCursor(cursor);/*  w ww.  j  a  v a2  s.  c om*/

    ListView listView = getListView();
    int count = listView.getCount();
    String fdroid = loader.getContext().getPackageName();
    for (int i = 0; i < count; i++) {
        Cursor c = ((Cursor) listView.getItemAtPosition(i));
        String packageName = c.getString(c.getColumnIndex(DataColumns.APP_ID));
        if (TextUtils.equals(packageName, fdroid)) {
            listView.setItemChecked(i, true); // always include Keude
        } else {
            for (String selected : KeudeApp.selectedApps) {
                if (TextUtils.equals(packageName, selected)) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    }

    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}

From source file:org.fdroid.fdroid.views.fragments.SelectLocalAppsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
    adapter.swapCursor(cursor);//from   w  w w  . j a  v  a2s  .  c om

    ListView listView = getListView();
    int count = listView.getCount();
    String fdroid = loader.getContext().getPackageName();
    for (int i = 0; i < count; i++) {
        Cursor c = ((Cursor) listView.getItemAtPosition(i));
        String packageName = c.getString(c.getColumnIndex(DataColumns.APP_ID));
        if (TextUtils.equals(packageName, fdroid)) {
            listView.setItemChecked(i, true); // always include FDroid
        } else {
            for (String selected : FDroidApp.selectedApps) {
                if (TextUtils.equals(packageName, selected)) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    }

    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}

From source file:com.ternup.caddisfly.fragment.DetailsFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {/*  ww  w .  j  a  v  a  2 s  .com*/
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            fm.executePendingTransactions();
        } else {
            Fragment fragment = new HomeFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.replace(R.id.container, fragment, "0");
            ft.addToBackStack(null);
            ft.commit();
            fm.executePendingTransactions();
            ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
            drawerList.setItemChecked(0, true);
            drawerList.setSelection(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*w w w  .ja v a2 s .com*/
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) {
                CapstoneControlActivity.userChanged = true;
                // 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();
                // clear the module list so that a new one will get found
                CapstoneControlActivity.modules.clear();
                // instead of finish() go back to the AccountsActivity for
                // new login.
                CapstoneControlActivity.googleUserName = (String) account.getText();
                Intent myIntent = new Intent(v.getContext(), SplashActivity.class);
                startActivity(myIntent);
                myIntent = new Intent(v.getContext(), CapstoneControlActivity.class);
                startActivity(myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            }
        });
    }
}

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

/**
 * Sets up the 'connect' screen content.
 *//*w w w  .  j a  v a2 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:falcofinder.android.fuehrerschein.chat.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from www  .  j av  a 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);

        /* 
         * rimuovo aggiunta account perche' disponible da versione 2.2
         * ma voglio compatibilita' con 2.1
        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:com.ternup.caddisfly.fragment.DetailsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle(R.string.details);
    mContext = getActivity();/* w  w w .j  a v a 2  s.c  o  m*/

    ListView listView = getListView();

    mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY);

    View header = getActivity().getLayoutInflater().inflate(R.layout.fragment_result, null, false);

    mPpmText = (TextView) header.findViewById(R.id.ppmText);
    mDateView = (TextView) header.findViewById(R.id.testDate);
    mTitleView = (TextView) header.findViewById(R.id.titleView);
    mResultTextView = (TextView) header.findViewById(R.id.result);
    mAddressText = (TextView) header.findViewById(R.id.address1);
    mAddress2Text = (TextView) header.findViewById(R.id.address2);
    mAddress3Text = (TextView) header.findViewById(R.id.address3);
    mSourceText = (TextView) header.findViewById(R.id.sourceType);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);

    mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY);
    mId = getArguments().getLong(getString(R.string.currentTestId));
    mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1);

    File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, mFolderName, false));

    long locationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1);

    final ArrayList<String> imagePaths = FileUtils.getFilePaths(getActivity(), mFolderName, "/small/",
            locationId);

    if (mId > -1) {
        if (!directory.exists()) {
            Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId);
            mContext.getContentResolver().delete(uri, null, null);
            goBack();
        } else if (imagePaths.size() > 0) {
            displayResult();
        } else {
            FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName);
            goBack();
        }
    }

    ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
    drawerList.setItemChecked(-1, true);
    drawerList.setSelection(-1);

    assert listView != null;
    listView.addHeaderView(header);

    // Gradient shading for title
    assert header != null;

    //Collections.sort(imagePaths);

    GalleryListAdapter adapter = new GalleryListAdapter(getActivity(), mTestTypeId, mId, imagePaths, true);
    setListAdapter(adapter);

    Shader textShader = new LinearGradient(0, 0, 0, mTitleView.getPaint().getTextSize(),
            new int[] { getResources().getColor(R.color.textGradientStart),
                    getResources().getColor(R.color.textGradientEnd) },
            new float[] { 0, 1 }, Shader.TileMode.CLAMP);
    mTitleView.getPaint().setShader(textShader);

}

From source file:com.nest5.businessClient.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from   w  w  w  .ja v a  2 s.  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) {
                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();
            }
        });
    }

    // internetConnectionStatus = (ImageView) findViewById(R.id.header_connection_status);
    SharedPreferences prefs = Util.getSharedPreferences(mContext);
    if (!isNetworkAvailable()) {
        internetConnectionStatus.setImageResource(R.drawable.error);

        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_DISCONNECTED).commit();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "No tienes una conexin a internet activa. Habiltala haciendo click en aceptar y seleccionando luego una red.")
                .setCancelable(false).setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
                        startActivityForResult(intent, 1);
                    }
                }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();

    } else {
        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_CONNECTED).commit();
    }
}

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ListView list = (ListView) parent;
    int count = mAdapter.getCount();

    if (list.isItemChecked(count - 1)) {
        list.setItemChecked(count - 1, false);
        createNewGroup();//w w w.  ja v  a  2s . c o m
        return;
    }

    for (int i = 0; i < count; i++) {
        mAdapter.getItem(i).setChecked(list.isItemChecked(i));
    }

    // First remove the memberships that have been unchecked
    ArrayList<RawContactDelta.ValuesDelta> entries = mState.getMimeEntries(GroupMembership.CONTENT_ITEM_TYPE);
    if (entries != null) {
        for (RawContactDelta.ValuesDelta entry : entries) {
            if (!entry.isDelete()) {
                Long groupId = entry.getGroupRowId();
                if (groupId != null && groupId != mFavoritesGroupId
                        && (groupId != mDefaultGroupId || mDefaultGroupVisible) && !isGroupChecked(groupId)) {
                    entry.markDeleted();
                }
            }
        }
    }

    // Now add the newly selected items
    for (int i = 0; i < count; i++) {
        GroupSelectionItem item = mAdapter.getItem(i);
        long groupId = item.getGroupId();
        if (item.isChecked() && !hasMembership(groupId)) {
            RawContactDelta.ValuesDelta entry = RawContactModifier.insertChild(mState, mKind);
            entry.setGroupRowId(groupId);
        }
    }
    updateView();
}