It is possible using Dialog class but I do not want it that way. Instead I want it to be done by using PopupWindow class which gets popped up on startup and display some message on the popup. I am helpless, just can not getting this after spending many days behind it. Hope I get it here. Please and Thanks. Also look at below snippet if you didn’t get what I want..
public class PopupActivity extends Activity implements OnClickListener {
LinearLayout ll = new LinearLayout(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(ll);
}
protected void onStart() {
super.onStart();
final PopupWindow pw;
Button button = new Button(this);
button.setText("Hello");
pw = new PopupWindow(button, 245, 284, true);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
pw.dismiss();
}
});
pw.showAsDropDown(ll, 10, -50);
}
}
Above code gives me FORCE CLOSE :/ Help guys..
this is how you may show a popup window.
main.xml
popup_layout.xml
main.java
The idea is that your popup will be displayed once your activity is loaded, otherwise it will produce exception Unable to add window — token null is not valid; is your activity running?. Unless you show popup on a button click, that is the reason I’m showing it after a delay of 100 milliseconds (which is almost unnoticeable).