我将把我的代码放在这里,大部分都可以正常工作。我尝试动态地从用户中插入服务团队的名称。我尝试创建一个算法,将名称的第二个值(整数)改组,然后使用textview将它们设置为独立的团队
public void getListToCreateLists(ArrayList<Player> bigList, int teams, double avg) {
//bigList = number of Players the user insert;
// teams = number of teams the user insert;
// avg = the avarge of all Players.getnum() / teams;
//object.getnum() = Player (object) int num (value);
int z = 0;
ArrayList<Player>[] arrayLists = (ArrayList<Player>[]) new ArrayList[teams];
for (int i = 0; i < teams; i++) {
arrayLists[i] = new ArrayList<Player>();
onCreateTeamsView(arrayLists[i]);
if (z != 0) {
z = 0;
}
Collections.shuffle(bigList);
for (int j = 0; j < bigList.size(); j++) {
Player current = bigList.get(j);
for (; z <= avg; z++) {
if (checkPlayerIfExists(current.getName(), arrayLists[i]) == false) {
arrayLists[i].add(current);
z += current.getNum();
bigList.remove(current);
break;
}
}
}
}
}
private void onCreateTeamsView(ArrayList<Player> arrayList) {
for (int i = 0; i < arrayList.size(); i++) {
TextView tv = new TextView(getContext());
tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
tv.setText(i +"\n");
mLinearLayout.addView(tv);
}
这是假定创建此算法的方法。 对于将帮助我完成这段代码的人,我将感到非常感谢。有任何疑问或更多代码可以查看我是否有空