0

fragmentのコンテンツをどのように動的に変更することが可能ですか?TabLayoutです。たとえば、現在のフラグメントにリストがあり、リストが変更されている場合、フラグメントレイアウトを更新する方法は?あなたの質問は言うあたりFragment問題ではありません(New >>Activity >>Tabbed Activityから選択)コードTabLayoutで現在のフラグメントのデータを変更する方法は?

public static class PlaceholderFragment extends Fragment { 
    /** 
    * The fragment argument representing the section number for this 
    * fragment. 
    */ 
    private static final String ARG_SECTION_NUMBER = "section_number"; 

    public PlaceholderFragment() { 
    } 

    /** 
    * Returns a new instance of this fragment for the given section 
    * number. 
    */ 
    public static PlaceholderFragment newInstance(int sectionNumber) { 
     PlaceholderFragment fragment = new PlaceholderFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(ARG_SECTION_NUMBER, sectionNumber); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_main, container, false); 
     TextView textView = (TextView) rootView.findViewById(R.id.section_label); 
     int areaID = getArguments().getInt(ARG_SECTION_NUMBER); 
     textView.setText(getString(R.string.section_format, areaID)); 
     return rootView; 
    } 
} 

/** 
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
* one of the sections/tabs/pages. 
*/ 
public class SectionsPagerAdapter extends FragmentPagerAdapter { 

    public SectionsPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int position) { 
     // getItem is called to instantiate the fragment for the given page. 
     // Return a PlaceholderFragment (defined as a static inner class below). 
     return PlaceholderFragment.newInstance(position + 1); 
    } 

    @Override 
    public int getCount() { 
     // Show 3 total pages. 
     return 3; 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     switch (position) { 
      case 0: 
       return "SECTION 1"; 
      case 1: 
       return "SECTION 2"; 
      case 2: 
       return "SECTION 3"; 
     } 
     return null; 
    } 
} 
+0

メソッドを呼び出して、あなたがやろうとしているもので、もう少し具体的だろうか? – Mauker

+0

@Mauker私はArrayListとListViewを持っており、ArrayListが変更されたときに、その変更されたArrayListを現在のフラグメントに表示したい –

答えて

1

を生成ここで

がデフォルトです。 ListViewを使用しているので、あらかじめ定義されたアダプタを使用するか、独自のカスタムアダプタを作成することができます。カスタムの作成方法については、this answer of mineを確認してください。

しかし、あなたがする必要があります長い話を短く:どちらか

  • this questionに思えるとして)ArrayAdapterを使用するか、私の答えに前述のように、独自に作成します。あなたは、アダプタ/データセットを変更

  • たびに、myAdapter#notifyDataSetChanged();

関連する問題