Note that there are some explanatory texts on larger screens.

plurals
  1. POusing checkbox to filter contacts and get phone number
    primarykey
    data
    text
    <p>I am working on an app that works similar to the default text messaging app on all Android phones. My problem is selecting more than one user to send an SMS message to. What I have done so far is stored my contacts as listview items with check boxes. Now I just need to get the phone numbers from the selected contacts.</p> <p>So what I am having trouble on doing. 1) Pulling a phone number from the contacts displayed in my listview 2)displaying that number in a textview in a new activity</p> <p>Sorry if my code is difficult to understand, please ask if you need clerification.</p> <p>This is the XML in which the listview is shown, called contact_manager.xml: </p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ListView android:id="@+id/contactList" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /&gt; &lt;Button android:id="@+id/showInvisible" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/showInvisible" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is my Activity that calls everything together.</p> <pre><code>public final class ContactManager extends Activity { public static final String TAG = "ContactManager"; private ListView mContactList; private boolean mShowInvisible; private Button mShowInvisibleControl; /** * Called when the activity is first created. Responsible for initializing * the UI. */ @Override public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "Activity State: onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.contact_manager); // Obtain handles to UI objects mContactList = (ListView) findViewById(R.id.contactList); mShowInvisibleControl = (Button) findViewById(R.id.showInvisible); // Initialize class properties mShowInvisible = false; // mShowInvisibleControl.setChecked(mShowInvisible); mShowInvisibleControl.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { } }); populateContactList(); } /** * Populate the contact list based on account currently selected in the * account spinner. */ private void populateContactList() { // Build adapter with contact entries Cursor cursor = getContacts(); String[] fields = new String[] { ContactsContract.Data.DISPLAY_NAME }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor, fields, new int[] { R.id.contactEntryText }); mContactList.setAdapter(adapter); } /** * Obtains the contact list for the currently selected account. * * @return A cursor for for accessing the contact list. */ private Cursor getContacts() { // Run query Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible ? "0" : "1") + "'"; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; return managedQuery(uri, projection, selection, selectionArgs, sortOrder); } </code></pre> <p>contact_entry.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;CheckBox android:id="@+id/contactEntryText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+id/contactEntryText" /&gt; &lt;/LinearLayout&gt; &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ListView android:id="@+id/contactList" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /&gt; &lt;Button android:id="@+id/showInvisible" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/showInvisible" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is my invite_text.xml This is actually the text view i want to input the numbers into so i can send a mass text message. </p> <pre><code> &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/contacts" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:gravity="center" android:paddingBottom="10dp" android:paddingLeft="10dp" android:paddingTop="10dp" android:text="@string/contacts" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;!-- android:textColor="#fff" android:background="@drawable/header" for header background --&gt; &lt;Button android:id="@+id/contactsButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/contacts" /&gt; &lt;/RelativeLayout&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/enter_contact" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;AutoCompleteTextView android:id="@+id/contactnumber" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/to" &gt; &lt;requestFocus /&gt; &lt;/AutoCompleteTextView&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/message_to_send" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;EditText android:id="@+id/invite_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/message_join" /&gt; &lt;Button android:id="@+id/sendtxt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="doLaunchContactPicker" android:text="@string/send_txt" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>If you need me to post any more information, please ask.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload