我正在開發一款類似於所有Android手機上的默認短信應用的應用。我的問題是選擇多個用戶發送短信到。到目前爲止,我所做的工作是使用複選框將我的聯繫人存儲爲列表視圖項目。現在我只需要從選定的聯繫人中獲取電話號碼。使用複選框來過濾聯繫人並獲取電話號碼
所以我在做什麼麻煩。 1)拉在我的列表視圖 2顯示的聯繫人顯示在一個新的活動在一個TextView這個數字的電話號碼)
很抱歉,如果我的代碼是很難理解,請詢問您是否需要clerification。
這是在列表視圖中顯示的XML,叫contact_manager.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/contactList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/showInvisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/showInvisible" />
</LinearLayout>
這是我的活動,共同呼籲一切。
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);
}
contact_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/contactEntryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/contactEntryText" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/contactList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/showInvisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/showInvisible" />
</LinearLayout>
這是我的invite_text.xml這實際上是我想要輸入的數字變成這樣我就可以發送羣發短信文本視圖。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<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" />
<!-- android:textColor="#fff" android:background="@drawable/header" for header background -->
<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" />
</RelativeLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/enter_contact"
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/contactnumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/to" >
<requestFocus />
</AutoCompleteTextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/message_to_send"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/invite_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/message_join" />
<Button
android:id="@+id/sendtxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="doLaunchContactPicker"
android:text="@string/send_txt" />
</LinearLayout>
</ScrollView>
如果你需要我發佈任何詳細信息,請詢問。
仍然還沒有解決這問題:( – 2012-04-01 02:29:56
你好,請張貼合作ntact_entry.xml佈局文件 – 2012-04-06 07:18:38
關於我的問題的我的.xml代碼已發佈,如果您有更多的問題,請在這裏發帖 – 2012-04-07 03:18:19