@Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder vh; final Computation comp = data.get(position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.list_comps, parent, false); vh = new ViewHolder(); vh.name = (TextView) convertView.findViewById(R.id.comp_name_text); vh.description = (TextView) convertView.findViewById(R.id.comp_desc_text); vh.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); } vh.name.setText(comp.getName()); vh.description.setText(comp.getTopics()); vh.checkBox.setTag(position); vh.checkBox.setChecked(checkedState[position]); vh.checkBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int pos = (int) buttonView.getTag(); checkedState[pos] = isChecked; } }); return convertView; }
public void addSelectedToDatabase(Context context) { List<Computation> selected = SetupCompsFragment.getSelectedComps(); TworkDBHelper db = TworkDBHelper.getHelper(context); for (Computation comp : selected) { db.addComputation( comp.getId(), comp.getName(), comp.getDescription(), comp.getTopics(), TworkDBHelper.COMP_STATUS_ACTIVE); Log.i("SQLite", "added" + comp.getName()); } }