0

The code below works perfect:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button) this.findViewById(R.id.btn1);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            method.show(v);
        }
    });
}

However, I need to get View without using onClick

The code below does not work

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button) this.findViewById(R.id.btn1);

    method.show(button);
}

How can I get the same View as passed to button.onClick?

Thank you very much.

Chilledrat
  • 2,593
  • 3
  • 28
  • 38
  • 1
    Your code looks valid. What do you mean by "the code below does not work". Nothing happens? It throws an exception? Or what? – Brayden May 30 '12 at 20:13
  • what you want we can't understand u? be more specific!! public void onClick(View v) the argument here is the view that was clicked – K_Anas May 30 '12 at 20:15
  • @Brayden I get the following error: android.view.WindowManager $ BadTokenException: Unable to add window - token null is not valid; WindowManager not recognized button as a View – Cris Marinho May 30 '12 at 20:22
  • What line do you get that at? You should post the full stack trace. – Brayden May 30 '12 at 20:24
  • can u show your import for Button? – Grey May 30 '12 at 20:28
  • The method opens a popup on the screen The error occurs on this line: PopupWindow.showAtLocation (parentView, Gravity.NO_GRAVITY, xpos, ypos); View parentView where is the button. method but only works with onClick (View v). – Cris Marinho May 30 '12 at 20:39

1 Answers1

1

I'm afraid you can't show a PopupWindow from onCreate().

Check out this answer

Community
  • 1
  • 1
Ole
  • 7,899
  • 2
  • 29
  • 34
  • Perfect. was just that. Runnable in the post, the button was given the attributes of screen position required. Thank you – Cris Marinho May 31 '12 at 13:37