首页 > android中fragmenttabhost+fragment+fragmentActivity的逻辑问题

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

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


在你的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 谢谢~

【热门文章】
【热门文章】