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.
This commit is contained in:
committed by
Jean-Baptiste Queru
parent
94d3d59106
commit
8f5361ba0d
@@ -41,6 +41,9 @@
|
||||
<Button android:id="@+id/checkbox_button"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:text="@string/alert_dialog_multi_choice"/>
|
||||
<Button android:id="@+id/checkbox_button2"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:text="@string/alert_dialog_multi_choice_cursor"/>
|
||||
<Button android:id="@+id/text_entry_button"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:text="@string/alert_dialog_text_entry"/>
|
||||
|
||||
@@ -263,6 +263,7 @@
|
||||
<string name="alert_dialog_select_button">List dialog</string>
|
||||
<string name="alert_dialog_single_choice">Single choice list</string>
|
||||
<string name="alert_dialog_multi_choice">Repeat alarm</string>
|
||||
<string name="alert_dialog_multi_choice_cursor">Send Call to VoiceMail</string>
|
||||
<string name="alert_dialog_progress_button">Progress dialog</string>
|
||||
<string name="alert_dialog_text_entry">Text Entry dialog</string>
|
||||
<string name="alert_dialog_username">Name:</string>
|
||||
|
||||
@@ -28,6 +28,9 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
import android.database.Cursor;
|
||||
import android.provider.Contacts;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
|
||||
@@ -60,6 +63,7 @@ public class AlertDialogSamples extends Activity {
|
||||
private static final int DIALOG_SINGLE_CHOICE = 5;
|
||||
private static final int DIALOG_MULTIPLE_CHOICE = 6;
|
||||
private static final int DIALOG_TEXT_ENTRY = 7;
|
||||
private static final int DIALOG_MULTIPLE_CHOICE_CURSOR = 8;
|
||||
|
||||
private static final int MAX_PROGRESS = 100;
|
||||
|
||||
@@ -193,6 +197,28 @@ public class AlertDialogSamples extends Activity {
|
||||
}
|
||||
})
|
||||
.create();
|
||||
case DIALOG_MULTIPLE_CHOICE_CURSOR:
|
||||
String[] projection = new String[] {
|
||||
Contacts.People._ID,
|
||||
Contacts.People.NAME,
|
||||
Contacts.People.SEND_TO_VOICEMAIL
|
||||
};
|
||||
Cursor cursor = managedQuery(Contacts.People.CONTENT_URI, projection, null, null, null);
|
||||
return new AlertDialog.Builder(AlertDialogSamples.this)
|
||||
.setIcon(R.drawable.ic_popup_reminder)
|
||||
.setTitle(R.string.alert_dialog_multi_choice_cursor)
|
||||
.setMultiChoiceItems(cursor,
|
||||
Contacts.People.SEND_TO_VOICEMAIL,
|
||||
Contacts.People.NAME,
|
||||
new DialogInterface.OnMultiChoiceClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton,
|
||||
boolean isChecked) {
|
||||
Toast.makeText(AlertDialogSamples.this,
|
||||
"Readonly Demo Only - Data will not be updated",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
case DIALOG_TEXT_ENTRY:
|
||||
// This example shows how to add a custom layout to an AlertDialog
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
@@ -281,6 +307,14 @@ public class AlertDialogSamples extends Activity {
|
||||
}
|
||||
});
|
||||
|
||||
/* Display a list of checkboxes, backed by a cursor */
|
||||
Button checkBox2 = (Button) findViewById(R.id.checkbox_button2);
|
||||
checkBox2.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
showDialog(DIALOG_MULTIPLE_CHOICE_CURSOR);
|
||||
}
|
||||
});
|
||||
|
||||
/* Display a text entry dialog */
|
||||
Button textEntry = (Button) findViewById(R.id.text_entry_button);
|
||||
textEntry.setOnClickListener(new OnClickListener() {
|
||||
|
||||
Reference in New Issue
Block a user