views:

24

answers:

1

Hello all,

I have a conceptual question to ask:

I created a custom dialog (extends Dialog) and I want to draw a chart (dynamic data, not static) in the top third of the dialog.

What's the best (only?) way to approach this?

A) Get a canvas to the dialog and draw to it? Seems like I need access to the dialog's draw, yes, or can I do this outside of the draw?

B) Subclass a view within the dialog layout (e.g. LinearLayout) and override it's draw and draw the chart?

C) Other? I've read that one approach would be to draw to a bitmap and then blt (or equivalent) to the canvas. This sounds closer to what I want to do, as once I create the chart, I have no need to alter it (no direct user interaction).

I haven't yet found any good sample code that deals with custom drawing in a dialog, so if I'm missing something, an example would be great.

Thanks much,

Rich

A: 

Solved.

My solution was a hybrid of B/C above. Since I needed access to the view's draw() method, I created my own subclass of an ImageView (e.g., MyView).

From within the draw(), I can get the dynamic size of the ImageView as it appears in the dialog. Given the size, I can now perform draws scaled to the custom ImageView size within the dialog.

I had to remember to use the proper custom view XML syntax in the dialog layout (e.g. "com.avaliant.dialogtest.MyView" to replace "ImageView"). And, of course, in my dialog class, I had to set to view to the proper view class:

MyView test = (MyView)dialogView.findViewById(R.id.test);

Quite easy once I understood WHY I had to do what I had to do :).

Rich

richbl