我按照教程创建了一个像google playstore这样的布局。 但是我有一个异步方法,它返回一个带有类别的卡片列表。我想知道如何显示类别列表和这些类别的卡片,知道某些类别的卡片比其他类别少。
我的活动课程:
public class AccueilActivity extends Fragment implements AppCompatCallback {
ArrayList<SectionData> allSampleData;
public AccueilActivity() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
allSampleData = new ArrayList<SectionData>();
createDummyData();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
// View rootView = inflater.inflate(R.layout.activity_accueil, container, false);
// return rootView ;
RecyclerView my_recycler_view = (RecyclerView) inflater.inflate(R.layout.activity_accueil, container, false); //getView().findViewById(R.id.my_recycler_viewy);
my_recycler_view.setHasFixedSize(true);
RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(getContext(), allSampleData);
my_recycler_view.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
my_recycler_view.setAdapter(adapter);
return my_recycler_view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@覆盖 public void onDetach(){ super.onDetach(); } public void createDummyData(){
//String[] section = MainActivity.env_cat;
for (int i = 1; i <= 6; i++) {
SectionData dm = new SectionData();
dm.setHeaderTitle("section"+i);
ArrayList<SingleItem> singleItem = new ArrayList<SingleItem>();
for (int j = 0; j <= 5; j++) {
singleItem.add(new SingleItem("Item " + j, "URL " + j));
}
dm.setAllItemsInSection(singleItem);
allSampleData.add(dm);
}
}
@Override
public void onSupportActionModeStarted(ActionMode mode) {
}
@Override
public void onSupportActionModeFinished(ActionMode mode) {
}
@Nullable
@Override
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) {
return null;
}
}
我的asyncstask响应:
0:object
cat_id:1
cat_lib:"shopping"
card_lib: "cat 1"
url:"https://cdn1.iconfinder.com/data/icons/appicns/513/appicns_Chrome.png"
1:object
cat_id:1
cat_lib:"shopping"
card_lib: "cat 2"
url:"https://cdn1.iconfinder.com/data/icons/appicns/513/appicns_Chrome.png"
2:object
cat_id:2
cat_lib:"spat"
card_lib: "cat 1"
url:"https://cdn1.iconfinder.com/data/icons/appicns/513/appicns_Chrome.png"
3:object
cat_id:3
cat_lib:"sport"
card_lib: "cat 1"
url:"https://cdn1.iconfinder.com/data/icons/appicns/513/appicns_Chrome.png"
4:object
cat_id:3
cat_lib:"sport"
card_lib: "cat 2"
url:"https://cdn1.iconfinder.com/data/icons/appicns/513/appicns_Chrome.png"
答案 0 :(得分:0)