我创建了一个扩展JPanel的类。现在我想创建它的多个对象。我怎么能这样做?
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
private final SparseArray<SalesReportList> mPageReferences = new SparseArray<SalesReportList>();
@Override
public CharSequence getPageTitle(int position) {
String title = null;
switch (position) {
case 0:
title = "Mobile";
break;
case 1:
title = "Accessory";
break;
}
return title;
}
@Override
public Fragment getItem(int position) {
SalesReportList myFragment = SalesReportList.newInstance(position);
mPageReferences.put(position, myFragment);
// return new SalesReportList().newInstance(position);
return myFragment;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
mPageReferences.remove(position);
}
public SalesReportList getFragment(int key) {
return mPageReferences.get(key);
}
@Override
public int getCount() {
return 2;
}
}
无效。也许让课程没有延长并返回JPanel[] panel = new PanelDraggable [i] (100,100,100,150,scroll);
?
JPanel[]
答案 0 :(得分:3)
首先,声明所需object
-
PanelDraggable[] panel = new PanelDraggable [size];
接下来,验证每个对象 -
for (int i=0; i<=size; i++) {
panel[i] = new PanelDraggable(Your params here);
}