So my idea is to have a one list than have another list inside of it. The android grouping is not the solution I’m looking for. I don’t want them grouped.
The problem im having with memory leaks and all sorts of crazyness. Like the adapter iterating through the list multiple times. Below is my Adapter.
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;
}
}
Rewrite
It looks like you are creating new TextView balls regardless of the existing ones. You should see how many currently exist then add or remove the difference: