コード例 #1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      ViewHolder holder = null;
      // Log.v("ConvertView", String.valueOf(position));

      if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.preferences_info, null);

        holder = new ViewHolder();
        holder.code = (TextView) convertView.findViewById(R.id.code);
        holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
        convertView.setTag(holder);

        holder.name.setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View v) {
                CheckBox cb = (CheckBox) v;
                Preferencias Preferencias = (Preferencias) cb.getTag();
                Preferencias.setSelected(cb.isChecked());
              }
            });
      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      Preferencias Preferencias = preferenciasList.get(position);
      holder.code.setText(" (" + Preferencias.getNroIntPref() + ")");
      holder.name.setText(Preferencias.getNome());
      holder.name.setChecked(Preferencias.isSelected());
      holder.name.setEnabled(false);
      holder.name.setTag(Preferencias);
      return convertView;
    }
コード例 #2
0
 private void displayListView(ArrayList<Preferencias> preferenciasList) {
   for (Preferencias p : preferenciasList) {
     p.setSelected(p.isSelected());
   }
   dataAdapter = new MyCustomAdapter(this, R.layout.preferences_info, preferenciasList);
   ListView listView = (ListView) findViewById(R.id.prefListView);
   listView.setAdapter(dataAdapter);
 }