質問

  1. 私のフラグメントアクティビティに次のクラスは、strings.xmlからタブの名前を取得したいですが、メソッドgetString(int resId)を使用できません "エラーメッセージが表示されません"タイプコンテキストからの静的メソッドgetString(int)。
  2. メソッドpublic CharSequence getPageTitle(int position)このname = getString(R.string.mystring)のようになる必要があります。
  3. public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {
    
              public AppSectionsPagerAdapter(FragmentManager fm) {
                  super(fm);
              }
    
              @Override
              public Fragment getItem(int i) {
                  switch (i) {
                  case 0:
                      Fragment fragment = new Activity1();
                      return fragment;
    
                  case 1:
                      Fragment fragment1 = new Activity2();
                      return fragment1;
    
                  default:
                      return new Activity2();
                  }
              }
    
              @Override
              public int getCount() {
                  return 2;
              }
    
              public CharSequence getPageTitle(int position) {
                  String name = null;
                  if (position==0) {
                      name = "Movie Details";
                  }else if (position==1) {
                      name = "Movie Comments";
                  }
                  return name;
              }
          }
    
    .
役に立ちましたか?

解決

Contextを呼び出すためのgetResources().getString(int resID)オブジェクトが必要です。コンストラクタにContextを渡して、ここで

のように使用してみてください。
Context mContext;

public AppSectionsPagerAdapter(FragmentManager fm,Context context) {
          super(fm);
           mContext = context
      }
.

を使用してmContext.getResources().getString(int resID)

を使用します。

他のヒント

内部クラスである場合は、クラス定義からstaticキーワードを削除するだけです。

編集:これをしないでください - 下記のコメントを参照してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top