RecyclerView、Fragment

1.RecyclerView

ViewHolder
Adapter
LayoutManager
ItemDecoration
  .
  .
  .
当想通过ItemViewType的值来显示不同的内容时,先重写getItemViewType(int postion),之后会将getItemViewType()的返回值写入onCreateViewHolder(parent, viewType)中作为参数。在onCreateViewHolder()方法中调用viewType即可。


2.Fragment

activity_fragment




创建Fragment

public abstract class SingleFragmentActivity extends AppCompatActivity {
    /*需要实现此抽象方法*/
    protected abstract Fragment createFragment();

    @LayoutRes
    protected int getLayoutResId() {
        return R.layout.activity_fragment;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());

        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);

        if (fragment == null) {
            fragment = createFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_container, fragment)
                    .commit();
        }
    }

}

你可能感兴趣的:(RecyclerView、Fragment)