开发者

Getting the Context of the enclosing object

New to Java. I am trying to create an explicit Intent to launch send the user to a new tab and pass some data to it. The problem I think I am having is getting the Context of the parent object that I can pass to the Intent Constructor. "This" is not correct. The onCreate code is below. Any pointers to examples would be helpful

public void onCreate(Bundle savedInstanceState) {
    super.onCreat开发者_运维知识库e(savedInstanceState);
    setContentView(R.layout.quickactivity);

    final Button goButton = (Button) findViewById(R.id.go);
    goButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            Intent i = new Intent(this, TimeActivity.class);

        }
    });

}


You can also use:

Intent i = new Intent(v.getContext(), TimeActivity.class);

More info here


Use

<MyClassName>.this

instead. Replacing by the actual class in which this method resides

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜