开发者

Pro Android 2: What are getTextView() and registerMenu()?

Listing 3-33 in the acclaimed Pro Android 2 book (source code can be found here) references two functions of开发者_开发技巧 which definitions I haven't been able to find in either the Android SDK or all listings in the book itself:

  1. getTextView()
  2. registerMenu()

What are these functions and where can they be found?


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

        TextView tv = new TextView(this);
        tv.setText("Helloe, Android. Say Hello");
        setContentView(tv);
        registerForContextMenu(tv);
}

will fix the problem of those methods not existing.

And no book I have read on Android is without its typos, missing bits etc.

PS. the menu will be a menu that shows up when you press down on the 'TextView'.


If you want to add a ContextMenu to a TextView from your XML layout, you can use this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv = (TextView)findViewById(R.id.textViewId);
    registerForContextMenu(tv);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜