使用 TabHost 和按钮进行 Android 1.5 编程
我目前正在尝试 Android 1.5 SDK,并且在 TabHost 上看到了几个示例。 我想做的是使用每个选项卡上的不同按钮来完成其任务。
我尝试过的 正在使用 onClickListiner() 和 onClick()。 我认为这是所有开发人员都使用的,但每次按下按钮时,我都会在 LogCat 上收到空异常。 另外,我有每个 XML 布局,因此我将选项卡称为: tab.add(...setContent(R.id.firstTabLayout))
firstTabLayout = layout for Button and TextView.
使按钮/TextView 在 TabHost 下正常工作的最佳方法是什么?
I am currently trying out the Android 1.5 SDK and I have seen a couple of examples on TabHost.
What I am trying to do is to use a different button on each Tab to do its tasks.
What I tried
was using onClickListiner() and onClick(). I think this is what all the developers use, but I keep getting a null exception on the LogCat every time the button is pressed. Also I have each XML Layout so I call the Tab as : tab.add(...setContent(R.id.firstTabLayout))
firstTabLayout = layout for Button and TextView.
What would be the best way to make a button/TextView work properly under the TabHost?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之前设置选项卡式活动的方式
我不完全确定你的问题出在哪里,但这就是我在layout.xml
Tab.java
然后,您可以在选项卡内的任何视图上使用 findViewById() ,或者如果它们之间存在共享名称,您可以执行
findViewById(R.id.tab1).findViewById(R.id.text )
I'm not entirely sure where your problem is, but this is how I've set up my Tabbed activities before
layout.xml
Tab.java
Then, you can just use findViewById() on any views within the tabs, or if there are shared names between them, you can do
findViewById(R.id.tab1).findViewById(R.id.text)