所以我的想法是有一个列表而不是其中的另一个列表。android 分组不是我正在寻找的解决方案。我不希望他们分组。
我遇到的问题是内存泄漏和各种疯狂。就像适配器多次遍历列表一样。下面是我的适配器。
public class LotteryAdapter extends ArrayAdapter<LotteryBall> {
Context context;
public LotteryAdapter(Context context, int resourceId,
List<LotteryBall> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
LinearLayout ballpanel;
LinearLayout jackpotpanel;
TextView txtTitle;
TextView txtBall;
TextView txtJackpot;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LotteryBall rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.mainrow, null);
convertView.setBackgroundResource(R.layout.greenbackground);
holder = new ViewHolder();
holder.txtTitle= (TextView) convertView.findViewById(R.id.LotteryTitle);
holder.ballpanel = (LinearLayout) convertView.findViewById(R.id.balllayout);
holder.jackpotpanel = (LinearLayout) convertView.findViewById(R.id.jackpotlayout);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtTitle.setText(rowItem.title);
for(int i = 0;i < rowItem.balls.size();i++)
{
Ball ball = rowItem.balls.get(i);
if(ball != null){
TextView tv = new TextView(context); //<--problem with the context its causing the adapter to go crazy
tv.setText(ball.number);
tv.setTextColor(Color.BLACK);
tv.setBackgroundResource(R.drawable.yellowball);
holder.ballpanel.addView(tv);
}
}
//if jackpot
TextView tvjackpot = new TextView(context);
tvjackpot.setText("Current Jackpot: " + rowItem.amount);
TextView tvnextdrawing = new TextView(context);
tvjackpot.setText("Next Drawing: " + rowItem.nextdrawing);
TextView tvpreviousjackpot = new TextView(context);
tvjackpot.setText("Previous Jackpot: " + rowItem.lastamount);
View ruler = new View(context);
ruler.setBackgroundColor(Color.WHITE);
holder.jackpotpanel.addView(tvjackpot);
holder.jackpotpanel.addView(ruler);
holder.jackpotpanel.addView(tvnextdrawing);
//holder.ballpanel.addView(ruler);
holder.jackpotpanel.addView(tvpreviousjackpot);
return convertView;
}
}