development
修訂 | 8f5361ba0d9eeaded8bcf9d1b14dbcfce7cc13fb (tree) |
---|---|
時間 | 2009-08-27 00:48:03 |
作者 | Muthu Ramadoss <muthu.ramadoss@gmai...> |
Commiter | Jean-Baptiste Queru |
Enhancement: ApiDemos - App - Dialog - AlertDialog with MultipleChoices backed by Cursor
Added an example for using AlertDialog in Multichoice mode backed up by Cursor. This example can be used to test the following bug: http://code.google.com/p/android/issues/detail?id=955
AMEND:
Added a Toast to display readonly status of cursor, so data will not be updated.
Removed empty code blocks, which did nothing.
@@ -41,6 +41,9 @@ | ||
41 | 41 | <Button android:id="@+id/checkbox_button" |
42 | 42 | android:layout_width="fill_parent" android:layout_height="wrap_content" |
43 | 43 | android:text="@string/alert_dialog_multi_choice"/> |
44 | + <Button android:id="@+id/checkbox_button2" | |
45 | + android:layout_width="fill_parent" android:layout_height="wrap_content" | |
46 | + android:text="@string/alert_dialog_multi_choice_cursor"/> | |
44 | 47 | <Button android:id="@+id/text_entry_button" |
45 | 48 | android:layout_width="fill_parent" android:layout_height="wrap_content" |
46 | 49 | android:text="@string/alert_dialog_text_entry"/> |
@@ -263,6 +263,7 @@ | ||
263 | 263 | <string name="alert_dialog_select_button">List dialog</string> |
264 | 264 | <string name="alert_dialog_single_choice">Single choice list</string> |
265 | 265 | <string name="alert_dialog_multi_choice">Repeat alarm</string> |
266 | + <string name="alert_dialog_multi_choice_cursor">Send Call to VoiceMail</string> | |
266 | 267 | <string name="alert_dialog_progress_button">Progress dialog</string> |
267 | 268 | <string name="alert_dialog_text_entry">Text Entry dialog</string> |
268 | 269 | <string name="alert_dialog_username">Name:</string> |
@@ -28,6 +28,9 @@ import android.view.LayoutInflater; | ||
28 | 28 | import android.view.View; |
29 | 29 | import android.view.View.OnClickListener; |
30 | 30 | import android.widget.Button; |
31 | +import android.widget.Toast; | |
32 | +import android.database.Cursor; | |
33 | +import android.provider.Contacts; | |
31 | 34 | |
32 | 35 | import com.example.android.apis.R; |
33 | 36 |
@@ -60,6 +63,7 @@ public class AlertDialogSamples extends Activity { | ||
60 | 63 | private static final int DIALOG_SINGLE_CHOICE = 5; |
61 | 64 | private static final int DIALOG_MULTIPLE_CHOICE = 6; |
62 | 65 | private static final int DIALOG_TEXT_ENTRY = 7; |
66 | + private static final int DIALOG_MULTIPLE_CHOICE_CURSOR = 8; | |
63 | 67 | |
64 | 68 | private static final int MAX_PROGRESS = 100; |
65 | 69 |
@@ -193,6 +197,28 @@ public class AlertDialogSamples extends Activity { | ||
193 | 197 | } |
194 | 198 | }) |
195 | 199 | .create(); |
200 | + case DIALOG_MULTIPLE_CHOICE_CURSOR: | |
201 | + String[] projection = new String[] { | |
202 | + Contacts.People._ID, | |
203 | + Contacts.People.NAME, | |
204 | + Contacts.People.SEND_TO_VOICEMAIL | |
205 | + }; | |
206 | + Cursor cursor = managedQuery(Contacts.People.CONTENT_URI, projection, null, null, null); | |
207 | + return new AlertDialog.Builder(AlertDialogSamples.this) | |
208 | + .setIcon(R.drawable.ic_popup_reminder) | |
209 | + .setTitle(R.string.alert_dialog_multi_choice_cursor) | |
210 | + .setMultiChoiceItems(cursor, | |
211 | + Contacts.People.SEND_TO_VOICEMAIL, | |
212 | + Contacts.People.NAME, | |
213 | + new DialogInterface.OnMultiChoiceClickListener() { | |
214 | + public void onClick(DialogInterface dialog, int whichButton, | |
215 | + boolean isChecked) { | |
216 | + Toast.makeText(AlertDialogSamples.this, | |
217 | + "Readonly Demo Only - Data will not be updated", | |
218 | + Toast.LENGTH_SHORT).show(); | |
219 | + } | |
220 | + }) | |
221 | + .create(); | |
196 | 222 | case DIALOG_TEXT_ENTRY: |
197 | 223 | // This example shows how to add a custom layout to an AlertDialog |
198 | 224 | LayoutInflater factory = LayoutInflater.from(this); |
@@ -281,6 +307,14 @@ public class AlertDialogSamples extends Activity { | ||
281 | 307 | } |
282 | 308 | }); |
283 | 309 | |
310 | + /* Display a list of checkboxes, backed by a cursor */ | |
311 | + Button checkBox2 = (Button) findViewById(R.id.checkbox_button2); | |
312 | + checkBox2.setOnClickListener(new OnClickListener() { | |
313 | + public void onClick(View v) { | |
314 | + showDialog(DIALOG_MULTIPLE_CHOICE_CURSOR); | |
315 | + } | |
316 | + }); | |
317 | + | |
284 | 318 | /* Display a text entry dialog */ |
285 | 319 | Button textEntry = (Button) findViewById(R.id.text_entry_button); |
286 | 320 | textEntry.setOnClickListener(new OnClickListener() { |