Android 选项卡+;试图使用imgbutton从片段1中进行呼叫的滑动

Android 选项卡+;试图使用imgbutton从片段1中进行呼叫的滑动,android,android-fragments,Android,Android Fragments,我使用默认的标签+滑动布局设置了一个pp,我知道如何在不同的幻灯片上显示不同的内容 我遇到的问题是如何启动一个意图(使用imagebutton打电话) 图像按钮是片段1或幻灯片1,我不知道在哪里取消按钮,或者如何格式化代码 我能处理的最好的一个错误是: Gradle:错误:无法从静态上下文引用非静态方法findViewById(int) 我的代码如下: /** * A dummy fragment representing a section of the app, but that simp

我使用默认的标签+滑动布局设置了一个pp,我知道如何在不同的幻灯片上显示不同的内容

我遇到的问题是如何启动一个意图(使用imagebutton打电话)

图像按钮是片段1或幻灯片1,我不知道在哪里取消按钮,或者如何格式化代码

我能处理的最好的一个错误是:

Gradle:错误:无法从静态上下文引用非静态方法findViewById(int)

我的代码如下:

/**
 * A dummy fragment representing a section of the app, but that simply
 * displays dummy text.
 */
public static class DummySectionFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";

    public DummySectionFragment() {
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if ((getArguments().getInt(ARG_SECTION_NUMBER)==1)) {
            View view = inflater.inflate(R.layout.test, container, false);
            return view;

            ImageButton ib1;

            ib1 = (ImageButton) findViewById(R.id.ib1);

            // add button listener
            ib1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:0377778888"));
                    startActivity(callIntent);

                }

            });




        }

        if ((getArguments().getInt(ARG_SECTION_NUMBER)==2)) {
            View view = inflater.inflate(R.layout.test2, container, false);
            return view;
        }


        if ((getArguments().getInt(ARG_SECTION_NUMBER)==3)) {
            View view = inflater.inflate(R.layout.test3, container, false);
            return view;
        }

            else {
            TextView textView = new TextView(getActivity());
            textView.setGravity(Gravity.CENTER);
            textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
            return textView;
        }
    }
}

}

如果不是内部类,可以删除
DummySectionFragment
声明中的
static
。 另外,findViewById应该是
getView().findViewById
。我不是
片段方面的专家,但是试试这个。

if((getArguments().getInt(ARG\u SECTION\u NUMBER)==3)){View View View View=inflater.inflate(R.layout.test3,container,false);ImageButton newPage=(ImageButton)View.findViewById(R.id.ib1);newPage.setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v){Intent callIntent=newintent(Intent.ACTION_调用);callIntent.setData(Uri.parse(“tel:07*******”));startActivity(callIntent);
这是我的解决方案