I am sure there is not enough meaning here, so I hope someone can explain.
I want to create a popup when the user touches ImageView . I looked at AlertDialog and the docs say ...
If you want to display a more complex view, find a 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));
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 above, where I addView throws addView NullPointerException which makes me think that there is a problem with android.R.id.custom .
So, the question is what is wrong with the above, and is there also a better way to create your own pop-up window (possibly using the Dialog class or its extension)?
NOTE: I use only TextView in this example as a test, I want to add something more complex to my actual popup.
source share