سؤال

هل من الممكن بدء قائمة سياق على طريقة OnCreate؟ أعلم أنه من المحتمل أن يكون أخلاقيات التصميم السيئة ولكن لديّ رنيسي !! لقد جربت:

registerForContextMenu(this.getCurrentFocus());

لكن لا يعمل .. فهل لديه أي أفكار أفضل؟

شكرا كثيرا مسبقا!

@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);
هل كانت مفيدة؟

المحلول

عليك فعل registerForContextMenu() لبعض القطعة ، ثم استخدم openContextMenu(). ومع ذلك ، فإنني أتفق مع استنتاجك أن هذا تصميم سيء.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top