アンドロイドのContextMenuはのonCreateメソッドで起動しますか?
-
26-09-2019 - |
質問
それはのonCreateメソッドのコンテキストメニューを起動することは可能でしょうか?私はそのおそらく悪いデザインの倫理を知っているが、私は私のresonsを持っています!私が試した:
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()
を行う必要があります。しかし、私はこれは悪いデザインであることを、あなたの結論に同意します。
所属していません StackOverflow