0

TabLayout에 현재 fragment의 콘텐츠를 어떻게 동적으로 변경할 수 있습니까? 예를 들어, 현재 조각에 목록이 있고 목록이 변경된 경우 조각 레이아웃을 업데이트하는 방법은 무엇입니까?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

당신의 질문은 말 당 Fragment 문제가되지 않습니다 (New에서 선택 >>Activity >>Tabbed Activity) 코드를 생성합니다. ListView을 사용 중이므로 미리 정의 된 어댑터를 사용하거나 사용자 정의 어댑터를 만들 수 있습니다. 맞춤 설정 방법을 확인하는 방법은 this answer of mine을 확인하십시오.

  • 이 (this question에 보인다 등) ArrayAdapter를 사용하거나 직접 만들 어느 내 대답은 위에서 언급 한 바와 같이, :에

    그러나 긴 이야기 짧은 다음이 필요합니다.

  • 당신이 당신의 어댑터/데이터 세트를 수정할 때마다, 방법 myAdapter#notifyDataSetChanged();

관련 문제