看完布局和代码再说具体问题吧
ArrayList<FrameLayout> frameLayouts = new ArrayList<>();
MyOnItemClickListener onItemClickListener = new MyOnItemClickListener();
FrameLayout frameLayout1 = (FrameLayout) getLayoutInflater().inflate(R.layout.fragment_my, null);
kuwoAdapter1 = new SimpleAdapter(MainActivity.this, list1, R.layout.listview_item, new String[]{"id", "name", "artist"},
new int[]{R.id.txtMusicId, R.id.txtMusicName, R.id.txtMusicArtist});
((ListView) frameLayout1.findViewById(R.id.lvShow)).setAdapter(kuwoAdapter1);
((ListView) frameLayout1.findViewById(R.id.lvShow)).setOnItemClickListener(onItemClickListener);
swipeRefreshLayout1 = setSwipeRefreshLayout((SwipeRefreshLayout) frameLayout1.findViewById(R.id.swipeLayout));
getDate(1);
frameLayouts.add(frameLayout1);
FrameLayout frameLayout2 = (FrameLayout) getLayoutInflater().inflate(R.layout.fragment_my, null);
kuwoAdapter2 = new SimpleAdapter(MainActivity.this, list2, R.layout.listview_item, new String[]{"id", "name", "artist"},
new int[]{R.id.txtMusicId, R.id.txtMusicName, R.id.txtMusicArtist});
((ListView) frameLayout2.findViewById(R.id.lvShow)).setAdapter(kuwoAdapter2);
((ListView) frameLayout2.findViewById(R.id.lvShow)).setOnItemClickListener(onItemClickListener);
swipeRefreshLayout2 = setSwipeRefreshLayout((SwipeRefreshLayout) frameLayout2.findViewById(R.id.swipeLayout));
getDate(2);
frameLayouts.add(frameLayout2);
FrameLayout frameLayout3 = (FrameLayout) getLayoutInflater().inflate(R.layout.fragment_my, null);
kuwoAdapter3 = new SimpleAdapter(MainActivity.this, list3, R.layout.listview_item, new String[]{"id", "name", "artist"}, new int[]{R.id.txtMusicId, R.id.txtMusicName, R.id.txtMusicArtist});
((ListView) frameLayout3.findViewById(R.id.lvShow)).setAdapter(kuwoAdapter3);
((ListView) frameLayout3.findViewById(R.id.lvShow)).setOnItemClickListener(onItemClickListener);
swipeRefreshLayout3 = setSwipeRefreshLayout((SwipeRefreshLayout) frameLayout3.findViewById(R.id.swipeLayout));
getDate(3);
frameLayouts.add(frameLayout3);
FrameLayout frameLayout4 = (FrameLayout) getLayoutInflater().inflate(R.layout.fragment_my, null);
kuwoAdapter4 = new SimpleAdapter(MainActivity.this, list4, R.layout.listview_item, new String[]{"id", "name", "artist"}, new int[]{R.id.txtMusicId, R.id.txtMusicName, R.id.txtMusicArtist});
((ListView) frameLayout4.findViewById(R.id.lvShow)).setAdapter(kuwoAdapter4);
((ListView) frameLayout4.findViewById(R.id.lvShow)).setOnItemClickListener(onItemClickListener);
swipeRefreshLayout4 = setSwipeRefreshLayout((SwipeRefreshLayout) frameLayout4.findViewById(R.id.swipeLayout));
getDate(4);
frameLayouts.add(frameLayout4);
FrameLayout frameLayout5 = (FrameLayout) getLayoutInflater().inflate(R.layout.fragment_my, null);
kuwoAdapter5 = new SimpleAdapter(MainActivity.this, list5, R.layout.listview_item, new String[]{"id", "name", "artist"}, new int[]{R.id.txtMusicId, R.id.txtMusicName, R.id.txtMusicArtist});
((ListView) frameLayout5.findViewById(R.id.lvShow)).setAdapter(kuwoAdapter5);
((ListView) frameLayout5.findViewById(R.id.lvShow)).setOnItemClickListener(onItemClickListener);
swipeRefreshLayout5 = setSwipeRefreshLayout((SwipeRefreshLayout) frameLayout5.findViewById(R.id.swipeLayout));
getDate(5);
frameLayouts.add(frameLayout5);
总是重复这段代码感觉很恶心,有没有优雅的方式,具体的代码在这里
自己摸索的,还望大神指点。
哈哈,你早该用 https://github.com/hackware19... 了。
用TabLayout+ViewPager+Fragment解决
列表封装到Fragment中