java - Android ActionBarSherlock 选项卡 : Fragments View

标签 java android actionbarsherlock

我在 ActionBarSherlock 上遇到 fragment 和 View 问题:

我已经成功实现了 2 个选项卡,这些选项卡打开了我的 fragment View 。

public class AFragment extends SherlockFragment {

private ImageButton imageButton1;
private ImageButton imageButton2;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment


    return inflater.inflate(R.layout.activity_afragment, container, false);



}
}

这是我的代码,布局显示一个 TextView 和 2 个 ImageButtons。我想声明图像按钮,如 imagebutton = (ImageButton) findViewById(R.id.imagebutton1);但这在 findViewById 处给了我一个错误。我尝试了 AFragment Activity 中的每个位置,但仍然存在相同的错误。我还尝试添加 OnCreate 函数,但这也不起作用......那么我需要将代码放在哪里才能使该 View 工作?谢谢!

最佳答案

您应该声明一个包含您的 View 的变量,进行所需的声明和修改,然后返回 View

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.activity_afragment, container, false);
    ImageButton imageButton = (ImageButton) v.findViewById(R.id.imagebutton1); 
    return v;

}

关于java - Android ActionBarSherlock 选项卡 : Fragments View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11587931/

相关文章:

android - 创建自定义布局时丢失 ActionBar 标题

android + eclipse + maven + actionbarsherlock

android - 在具有 MenuItem.SHOW_AS_ACTION_ALWAYS 的 ActionBarSherlock 中将 TextWatcher 添加到 EditText

Java FX 8,无法设置文本字段的值

java - Tomcat 为带空格的请求 URI 返回 505

android - RecyclerView 项目动画,onAnimationFinished 被调用,但没有 onAnimationStarted。为什么?

android - Fragment 内的 MapView - 指定的子项已有父项

java - 获得拥有 1000 个关注者的推特用户

java - 在数组中查找并搜索 double 并返回其索引?这是数组元素交换方法吗?)

android - DragSortListView 在用户确认后删除项目