开发者

Event listener on view in tabs when not extending TabActivity

开发者 https://www.devze.com 2023-02-10 03:12 出处:网络
I have an android app that extends a MapActivity, so I can\'t extend TabActivity. I am inflating the content of the tabs dynamically, and everything looks good.

I have an android app that extends a MapActivity, so I can't extend TabActivity. I am inflating the content of the tabs dynamically, and everything looks good.

The problem that I'm running in to is that I get a NullPointerException when trying to bind event listeners to the views that were inflated into a tab past the first 开发者_运维问答tab.

Example:

myButtonInTab2 = (Button)this.findViewById(R.id.mybuttonintab2);
myButtonInTab2.setOnClickListener(new OnClickListener(){
    public void(View v){
        ///blah blah blah
    }
});


If you are "inflating the content of the tabs dynamically", you should be calling findViewById() on the result of the inflate() call, for any widgets in that tab.

0

精彩评论

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