0

デフォルトのタブ + スワイプ レイアウトを使用して pp をセットアップしました。さまざまなスライドにさまざまなコンテンツを表示する方法を見つけました。

私が抱えている問題は、インテントを開始する方法です(イメージボタンを使用して電話をかける.

画像ボタンはフラグメント 1 またはスライド 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;
        }
    }
}

}

4

1 に答える 1

1

これが内部クラスでない場合staticは、宣言内のを削除してください。DummySectionFragmentまた、findViewById は である必要がありますgetView().findViewById。私は専門家ではありませんFragmentが、これを試してください。

于 2013-09-13T00:39:29.580 に答える