【问题标题】:Android ActionBarSherlock Tabs: Fragments ViewAndroid ActionBarSherlock 选项卡:片段视图
【发布时间】:2012-07-21 07:06:04
【问题描述】:

我对 ActionBarSherlock 上的片段和视图有疑问:

我已经成功实现了 2 个选项卡,这些选项卡打开了我的片段视图。

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 函数,但这也不起作用......那么我需要将我的代码放在哪里才能使该视图工作?谢谢!

【问题讨论】:

    标签: java android actionbarsherlock


    【解决方案1】:

    你应该声明一个包含你的视图的变量,做你想要的声明和修改,然后返回视图

    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;
    
    }
    

    【讨论】:

    • 哇!谢谢亲爱的先生,这对我有用!多谢!你为我节省了 4 小时的电力搜索 :) (不幸的是,由于缺少声誉,我无法投票......)
    猜你喜欢
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 2016-02-04
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多