문제

is it possible to start a context menu on the onCreate method? I know its probably bad design ethics but I have my resons!! I've tried the:

registerForContextMenu(this.getCurrentFocus());

But its not working.. So does anyone have any better ideas?

Many thanks in advance!

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout layout = new LinearLayout(this);
    layout.setLayoutParams(new
    LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    //Button button = new Button(this);
    //button.setLayoutParams(new
    //LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    //button.setText("my button");

    TextView text = new TextView(this);
    text.setLayoutParams(new
    LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    layout.addView(text);
    setContentView(layout);

    registerForContextMenu(text);
    openContextMenu(layout);
도움이 되었습니까?

해결책

You need to do registerForContextMenu() for some widget, then use openContextMenu(). However, I agree with your conclusion that this is a bad design.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top