After 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:27 pm, greg <[email protected]> wrote: > My application has a ListView displaying some items that are > associated with different documents: > > // arrays.xml > <?xml version="1.0" encoding="utf-8"?> > <resources> > <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> > </string-array> > </resources> > > 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 > docs", > Toast.LENGTH_SHORT).show(); > showDialog(DIALOG_DOCS_AVAILABLE); > } > else > Toast.makeText(this, "long click position " + position + " has > no docs", > Toast.LENGTH_SHORT).show(); > > return true; > } > > @Override > protected Dialog onCreateDialog(int id) { > switch (id) { > case DIALOG_DOCS_AVAILABLE: > return new AlertDialog.Builder(this) > .setTitle(R.string.select_doc_dialog) > .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 > (R.array.select_doc_dialog_items); > Toast.makeText(List15.this, "You selected: " + which > + " , " + items[which], > Toast.LENGTH_SHORT).show(); > } > }) > .create(); > } > return null; > } > > @Override > protected void onPrepareDialog(int id, Dialog dialog) { > super.onPrepareDialog(id, dialog); > Toast.makeText(List15.this, "onPrepareDialog id: " + id, > Toast.LENGTH_SHORT).show(); > } > > - - - > > 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 R.java, 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, > Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

