1 创建fragment

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_arguments_support);

    if (savedInstanceState == null) {
        // First-time init; create fragment to embed in activity.
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        Fragment newFragment = MyFragment.newInstance("From Arguments");
        ft.add(R.id.created, newFragment);
        ft.commit();
    }
}

2 tools:text android:text区别

android:text --> what you would see while running the app

tools:text --> what you would see just on preview window (when you need to design layout, but won't it to see on layout in app)


xmlns:tools="http://schemas.android.com/tools"

tools可以告诉Android Studio,哪些属性在运行的时候是被忽略的,只在设计布局的时候有效。

3 RecyclerView.onBindViewHolder called only once


原因:Make sure you set layout_height =" wrap_content" of RecyclerView child item.

4 Only one item displaying in recycler view. 显示列表的时候,有三条记录,却仅仅显示第一条。

具体布局:<RecyclerView> <RelativeLayout/> <TextView/>

                </RecyclerView>

方案: Change height of LinearLayout to wrap_content in itemlist.xml

android:layout_height="wrap_content"

That means : RecyclerView and RelativeLayout both need to set

layout_height="wrap_content"

 5