I'm sure I'm missing the point here so I'm hoping someone can explain.
I want to create a popup when a user touches an ImageView
. I had a look at AlertDialog
and the docs say...
If you want to display a more complex view, look up the FrameLayout called "custom" and add your view to it:
...with the following code...
FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
So as a test I tried the following in my onCLick() method...
TextView tv = new TextView(this);
tv.setText("Hello World");
FrameLayout customFrameLayout = (FrameLayout) findViewById(android.R.id.custom);
customFrameLayout.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
The last line of the above where I'm calling addView
throws a NullPointerException
which makes me think there's a problem with android.R.id.custom
.
So the question is, what is wrong with the above and also is there a better way of creating a custom popup (perhaps by using the Dialog
class or extending it)?
NOTE: I'm only using TextView
in this example as a test, I want to add something more complex for my actual popup.
One option is to create an Activity
and style it using the dialog theme:
<activity android:theme="@android:style/Theme.Dialog">
See applying themes for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With