filtering dialog items in onPrepareDialog()

by greg » Tue, 11 Aug 2009 04:35:16 GMT

Sponsored Links
 My application has a ListView displaying some items that are
associated with different documents:

// arrays.xml
<?xml version="1.0" encoding="utf-8"?>
    <string-array name="select_doc_dialog_items">
        <item>doc type A</item>
        <item>doc type B</item>
        <item>doc type C</item>
        <item>doc type D</item>

The ListView implements an OnItemLongClickListener and displays the
available document types as follows:

        public boolean onItemLongClick(AdapterView<?> av, View v, int
position, long id) {
            mPositionActive = position;
            mListView.invalidate();  // TODO: increase efficiency by reducing
invalidate to one item

            if ((position%10) < 4) {
                Toast.makeText(this, "long click position " + position " has
                Toast.makeText(this, "long click position " + position + " has
no docs",

            return true;

    protected Dialog onCreateDialog(int id) {
        switch (id) {
            return new AlertDialog.Builder(this)
                .setItems(R.array.select_doc_dialog_items, new
DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int
which) {

                        /* User clicked so do some stuff */
                        String[] items = getResources().getStringArray
                        Toast.makeText(List15.this, "You selected: " + which
+ " , " + items[which],
        return null;

    protected void onPrepareDialog(int id, Dialog dialog) {
        super.onPrepareDialog(id, dialog);
        Toast.makeText(List15.this, "onPrepareDialog id: " + id,

- - -

I would like to modify onPrepareDialog to filter the dialog to display
only the document types relevant for the long clicked item (like a
context menu except that some long clicks will perform a different
task: expand or collapse the hierarchy displayed in the custom
ListView).  For example, if an item is long clicked that is associated
with only document types A and B, I would like the dialog to avoid
displaying document types C and D as dialog items?   However, looking
at, it is not clear to me what the id of an individual item in
the select_doc_dialog_items array would be.

Anyone have any tips on how to use onPrepareDialog() to filter
displayed dialog items?

Thanks and best regards,


filtering dialog items in onPrepareDialog()

by greg » Tue, 11 Aug 2009 07:44:14 GMT

 fter a little more reading, it seems possible to use the
AlertDialog's getListView() and then hide the unwanted ListView
items. However, an easier path appears to be generating a shortened
list of items during onCreateDialog() and then dismissing it with
removeDialog() ... so the next instance with possibly a different list
will be recreated by onCreateDialog().

On Aug 10, 4:27pm, greg <> wrote:

Sponsored Links

Other Threads

1. Launch Google Maps app

I'm trying to launch Google maps from my application.
I'm using:

GeoPoint center = _mapView.getMapCenter();
Uri uri = Uri.parse("geo:"+center.getLatitudeE6()
Log.d(LOG_TAG, "Launching Google Maps with Uri: ("+uri+")");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

I tested it with a map centered on somewhere in NYC, however Google
maps opens not centered there.
I followed Android Developer's site reference to use:
"geo:latitude,longitude" pattern.

the log that you see prints:
03-31 13:01:20.126: DEBUG/CarMapActivity(248): Launching Google Maps
with Uri: (geo:40763500,-73979305)

anyone knows what can be the problem?



2. Touchscreen support for 7 Inch LCD panel

Hello all,
We are working in OMAP3530 processor. We have changed the LCD size
from 480 x 272 to 800 x 480 .
We have changed the front panel parameters accordingly and we are able
to get Android screen properly.

Currently we are working in touchscreen . We are using ads7846 touch
screen controller.

We have tested Touch screen through tslib calibration after linux
booting. Its able to sense it.

But in Android it should not able to sense the proper positions.

we would like to know , how the xmin, xmax, ymin and ymax  parameter
values are calculated  for the new LCD resolution?

ie For 480 x 272 the following values are given in the board file

struct ads7846_platform_data ads7846_config = {
       .x_min                  = 0,
       .y_min                  = 0,
       .x_max                  = 3800,
       .y_max                  = 3800,
//      .x_max                  = 0x0fff,
//      .y_max                  = 0x0fff,

        .x_plate_ohms           = 180,
        .pressure_max           = 255,
        .debounce_max           = 20,
        .debounce_tol           = 10,
        .debounce_rep           = 1,
        .get_pendown_state      = ads7846_get_pendown_state,
        .keep_vref_on           = 1,
        .settle_delay_usecs     = 150,

We would like to know for the new LCD 800 x 480 , how this value
should be calculated?



3. finish parent activity from child

4. Harga milestones di malaysia :)

5. List providers - does it work for Android 1.5?

6. Unit-testing framework snippet

7. HTC bisa jadi Modem tidak???