android中fragmenttabhost+fragment+fragmentActivity的逻辑问题

新手上路,请多包涵

框架为:主类继承fragmentActivity,XML文件为fragmenttabhost+fragment+radiobutton的一个底部导航栏,点击radioButton动态切换fragment...
问题:在子fragment中,如何实现其加载的view的控件逻辑呢?我知道有些简单的可以view.findviewbyid()...
有些控件实例化需要上下文this,可是这个类继承的并不是Activity,而是fragment,并不适用上下文this,请问这时该如何实现其子fragment中view的控件逻辑?

阅读 4.5k
2 个回答

在你的fragment中拿到你想要的view即可

public class YourFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.details, container, false);
        Button button = (Button) view.findViewById(R.id.your_button);
        button.setOnClickListener(...);
        return view;
}
新手上路,请多包涵

请问解决了吗? 我也遇到这个问题了。715393162 谢谢~

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题