|
|
package com.example.PersonalCenter;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
import androidx.cardview.widget.CardView;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import com.example.cmknowledgegraph.R;
|
|
|
import com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class RecyclerViewFragment extends Fragment {
|
|
|
int flag;
|
|
|
AppCompatActivity appCompatActivity;
|
|
|
|
|
|
public void setAppCompatActivity(AppCompatActivity appCompatActivity) {
|
|
|
this.appCompatActivity = appCompatActivity;
|
|
|
}
|
|
|
|
|
|
public void setFlag(int flag) {
|
|
|
this.flag = flag;
|
|
|
}
|
|
|
|
|
|
public static Fragment newInstance(int flag, AppCompatActivity appCompatActivity){
|
|
|
RecyclerViewFragment recyclerViewFragment = new RecyclerViewFragment();
|
|
|
recyclerViewFragment.setFlag(flag);
|
|
|
recyclerViewFragment.setAppCompatActivity(appCompatActivity);
|
|
|
return recyclerViewFragment;
|
|
|
}
|
|
|
final List<Object> items = new ArrayList<>();
|
|
|
static final int ITEMS = 7;
|
|
|
|
|
|
RecyclerView mRecyclerView;
|
|
|
CardView mCardView;
|
|
|
@Override
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
return inflater.inflate(R.layout.fragment_recyclerview, container, false);
|
|
|
}
|
|
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
mRecyclerView=view.findViewById(R.id.recyclerView);
|
|
|
// mCardView = view.findViewById();
|
|
|
//需要根据网路请求发送数据,来请求一个页可以有多少文章条目,而且针对每一个tab,都要有不同的显示方式
|
|
|
for (int i=0;i<ITEMS;i++){
|
|
|
items.add(new Object());
|
|
|
}
|
|
|
|
|
|
|
|
|
//设置布局
|
|
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
|
|
|
linearLayoutManager.canScrollVertically();
|
|
|
mRecyclerView.setLayoutManager(linearLayoutManager);
|
|
|
|
|
|
mRecyclerView.setHasFixedSize(true);
|
|
|
//设置分割线
|
|
|
mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
|
|
|
//设置适配器
|
|
|
RecyclerViewPagerAdapter recyclerViewPagerAdapter = new RecyclerViewPagerAdapter(items,flag);
|
|
|
recyclerViewPagerAdapter.setAppCompatActivity(appCompatActivity);
|
|
|
mRecyclerView.setAdapter(recyclerViewPagerAdapter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
public void initdata(){
|
|
|
//初始化数据类,请求网络
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|