private String getSimlarId(final int position) {
    final ContactsAdapter contactsAdapter = (ContactsAdapter) getListAdapter();
    if (contactsAdapter == null) {
      return null;
    }

    final ContactDataComplete contact = contactsAdapter.getItem(position);
    return contact == null ? null : contact.simlarId;
  }
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
   // This swaps the new cursor into the adapter.
   if (loader.getId() == ContactsQuery.QUERY_ID) {
     mAdapter.swapCursor(data);
   }
 }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // This swaps the new cursor into the adapter.
    if (loader.getId() == ContactsQuery.QUERY_ID) {
      mAdapter.swapCursor(data);

      if (!TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) {
        // Selects the first item in results, unless this fragment has
        // been restored from a saved state (like orientation change)
        // in which case it selects the previously selected search item.
        if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) {
          // Creates the content Uri for the previously selected
          // contact by appending the
          // contact's ID to the Contacts table content Uri
          final Uri uri =
              Uri.withAppendedPath(
                  Contacts.CONTENT_URI, String.valueOf(data.getLong(ContactsQuery.ID)));
          mOnContactSelectedListener.onContactSelected(uri);
          getListView().setItemChecked(mPreviouslySelectedSearchItem, true);
        } else {
          // No results, clear selection.
          onSelectionCleared();
        }
        // Only restore from saved state one time. Next time fall back
        // to selecting first item. If the fragment state is saved again
        // then the currently selected item will once again be saved.
        mPreviouslySelectedSearchItem = 0;
        mSearchQueryChanged = false;
      }
    }
  }
  @Override
  public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

    CheckBox checkbox = (CheckBox) v.findViewWithTag(position);
    if (checkbox.isChecked()) checkbox.setChecked(false);
    else checkbox.setChecked(true);

    // Gets the Cursor object currently bound to the ListView
    final Cursor cursor = mAdapter.getCursor();

    // Moves to the Cursor row corresponding to the ListView item that was
    // clicked
    cursor.moveToPosition(position);

    // Creates a contact lookup Uri from contact ID and lookup_key
    final Uri uri =
        Contacts.getLookupUri(
            cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY));

    // Notifies the parent activity that the user selected a contact. In a
    // two-pane layout, the
    // parent activity loads a ContactDetailFragment that displays the
    // details for the selected
    // contact. In a single-pane layout, the parent activity starts a new
    // activity that
    // displays contact details in its own Fragment.
    mOnContactSelectedListener.onContactSelected(uri);

    // If two-pane layout sets the selected item to checked so it remains
    // highlighted. In a
    // single-pane layout a new activity is started so this is not needed.

  }
 @Override
 public void onLoaderReset(Loader<Cursor> loader) {
   if (loader.getId() == ContactsQuery.QUERY_ID) {
     // When the loader is being reset, clear the cursor from the adapter. This allows the cursor
     // resources to be freed.
     mAdapter.swapCursor(null);
   }
 }
  @Override
  public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    // Gets the Cursor object currently bound to the ListView
    final Cursor cursor = mAdapter.getCursor();

    // Moves to the Cursor row corresponding to the ListView item that was clicked
    cursor.moveToPosition(position);

    // Creates a contact lookup Uri from contact ID and lookup_key
    final Uri uri =
        Contacts.getLookupUri(
            cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY));

    // NOTIFIES THE PARENT ACTIVITY that the user selected a contact. Then the parent activity
    // starts a new activity that
    // displays contact details in its own Fragment.
    mOnContactSelectedListener.onContactSelected(uri);
  }
Exemplo n.º 7
0
 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
   adapter.search(s.toString());
   adapter.notifyDataSetChanged();
 }
 @Nullable
 @OnTextChanged(R.id.search_key_contact)
 void searchContact() {
   contactsAdapter.setFilter(searchKeyContact.getText().toString());
 }