나는 전체 Fragment-way-of-thinking에 대해 다소 혼란스러워합니다. 나는 Google Play
app처럼 Fragments
으로 ViewPager
을 만드는 법에 대한 튜토리얼을 따라 갔다.ViewPager의 안드로이드 조각
public class SwipeyTabFragment extends SherlockFragment {
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
Log.e("FRAGMENT: ", "Hello World!");
}
public static Fragment newInstance(String title) {
SwipeyTabFragment f = new SwipeyTabFragment();
Bundle args = new Bundle();
args.putString("title", title);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_swipeytab, null);
final String title = getArguments().getString("title");
((TextView) root.findViewById(R.id.text)).setText(title);
return root;
}
}
나는 onCreateView
방법은 레이아웃 등 Button
, ListView
과 같은 controlls를 초기화 것을 알고 :
FragmentAdapter
private class SwipeyTabsPagerAdapter extends FragmentPagerAdapter implements SwipeyTabsAdapter {
private final Context mContext;
public SwipeyTabsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
this.mContext = context;
}
@Override
public Fragment getItem(int position) {
return SwipeyTabFragment.newInstance(TITLES[position]);
}
@Override
public int getCount() {
return TITLES.length;
}
public TextView getTab(final int position, SwipeyTabs root) {
TextView view = (TextView) LayoutInflater.from(mContext).inflate(R.layout.swipey_tab_indicator, root, false);
view.setText(TITLES[position]);
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mViewPager.setCurrentItem(position);
}
});
return view;
}
}
이 단지 텍스트와 Fragment
의 헤더를 설정하는 문자열 배열을 기반으로 새 탭을 구성합니다.
그래서 여기가 혼란 스럽습니다. 예를 들어, 레이아웃이 다른 여러 조각이 있고, 사용자가 Button
, Picture
등을 누르면 다른 상호 작용 방식이 필요하다고 말하십시오. 그렇게하려면 어떻게해야합니까?
감사합니다.
고마워요! 기본 코드 샘플, 특히 getItem 메소드에 대한 샘플 코드를 제공 할 시간이 있습니까, 어떻게해야하는지 잘 모르겠습니다. –