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"?>
<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

--~--~---------~--~----~------------~-------~--~----~



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 <sep...@eduneer.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Socket in AsyncTask - application crashesso the UI won't be blocked

You can register a handler in your code and send message to update  your UI
component in Handler. I used this way to solve a similar problem like urs
before. For exapmpel

  if (socket.isConnected()) {
                                       OutputStreamOut = new
ObjectOutputStream(socket.
getOutputStream());
                                       InputStreamIn = new
ObjectInputStream(socket.getInputStream());
                       // everything worked fine until here
                         //instead of doing this, send msg to a customized
handler
                        //statusTxt.setText("App is now connected to:\n" +
IP + " : "
                        mHandler.sendEmptyMessage(UPDATE TEXT); //use
something like this
+ Port); // CRASHING !!!!
                               connectBt.setText("Disconnect");
                               connected = true;
                               continueBt.setVisibility(0);
                       } else {









> 

2. Delete Call Log entry Exception

hi guys,

i have a BroadCastReceiver which will listen to incoming calls. and
once the call is finish or users ignores the call i'm deleting the
number from the CallLog. i have tested this with HTC TATTOO and it
works fine there.

but when i tested this with Motorola MilesTone i'm getting a exception

this is the Exception

06-21 13:34:02.365: ERROR/DatabaseUtils(1337): Writing exception to
parcel
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):
java.lang.UnsupportedOperationException: Cannot delete that URL:
content://call_log/calls/442
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
com.android.providers.contacts.CallLogProvider.delete(CallLogProvider.java:
197)
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
android.content.ContentProvider$Transport.delete(ContentProvider.java:
174)
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
android.content.ContentProviderNative.onTransact(ContentProviderNative.java:
180)
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
android.os.Binder.execTransact(Binder.java:287)
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
dalvik.system.NativeStart.run(Native Method)



06-21 13:34:02.381: ERROR/AndroidRuntime(1593): Uncaught handler:
thread main exiting due to uncaught exception
06-21 13:34:02.459: ERROR/AndroidRuntime(1593):
java.lang.UnsupportedOperationException: Cannot delete that URL:
content://call_log/calls/442

this is my code

public class CallListener extends BroadcastReceiver {
        private Context context;
        String phonenbr;
        TelephonyManager telManager;
        Handler handler = new Handler();

        @Override
        public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                this.context = context;
                        telManager = (TelephonyManager) context
                                        
.getSystemService(Context.TELEPHONY_SERVICE);
                        telManager.listen(new StateListener(),
                                        PhoneStateListener.LISTEN_CALL_STATE);

        }

        class StateListener extends PhoneStateListener {
                @Override
                public void onCallStateChanged(int state, String 
incomingNumber) {
                        // TODO Auto-generated method stub
                        // super.onCallStateChanged(state, incomingNumber);
                        switch (state) {
                        case TelephonyManager.CALL_STATE_RINGING:
                                break;
                        case TelephonyManager.CALL_STATE_IDLE:

                                listeneNativeInbox();
                                break;
                        case TelephonyManager.CALL_STATE_OFFHOOK:

                                break;
                        }
                }
        }
protected void listeneNativeInbox() {

                context.getContentResolver().registerContentObserver(
                                CallLog.Calls.CONTENT_URI, true, new 
MyInboxListener(handler));

                // Uri Sms = Uri.parse("content://sms/inbox");
                /*
                 * Cursor c = context.getContentResolver().query(
                 * CallLog.Calls.CONTENT_URI, null, null, null, null);
                 */
        }

        class MyInboxListener extends ContentObserver {

                public MyInboxListener(Handler handler) {
                        super(handler);
                        // TODO Auto-generated constructor stub
                }

                @Override
                public boolean deliverSelfNotifications() {
                        // TODO Auto-generated method stub
                        return false;
                }

                @Override
                public void onChange(boolean selfChange) {
                        // TODO Auto-generated method stub
                        boolean b = false;
                        Uri books = 
Uri.parse("content://com.sabretch.colorEyeD/SABRE");
                        Log.d("Authority", books.getAuthority());
                        Cursor cursor = 
context.getContentResolver().query(books, null,
                                        "Mobile" + "='" + phonenbr + "'", null,
                                        "category " + "DESC");
                        if (cursor != null) {
                                if (cursor.moveToNext()) {
                                        b = true;
                                }
                        }
                        Message msg = new Message();
                        msg.obj = "xxxxxxxxxx";
                        handler.sendMessage(msg);
                        Cursor cur = context.getContentResolver().query(
                                        CallLog.Calls.CONTENT_URI, null, null, 
null,
                                        CallLog.Calls._ID + " DESC");
                        cur.moveToNext();
                        long threadIdIn = cur
                                        
.getLong(cur.getColumnIndex(CallLog.Calls._ID));
                        Uri uri = 
ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI,
                                        threadIdIn);
                        if (b) {
                                int x = 
context.getContentResolver().delete(uri, null, null);
                                Log.d("FFFFFFFFFASSDSSDESD", 
Integer.toString(x));
                        }
                        System.exit(0);
                        // }
                }
        }
}

so do you have any idea about this??
NOTE:- works correctly in HTC tattoo but not in Motorola Milestone

regards,
Mike

-- 

3. Howto pass pointer to char parameter to kernel via copy_to_user()

4. HTC tattoo List separators and menu separator lines are not visible

5. HTC tattoo List separators and menu separator lines are not visible

6. Added Interface of is not resolving at runtime

7. URL links are not opened in HTML viewer