Tecnologia do Blogger.
RSS

[androidbrasil-dev] Re: CustomAdapter com CheckBox

Algo mais ou menos assim:

public void Remove(int position) {
        listaremove(position);
    }

Em quinta-feira, 26 de fevereiro de 2015 11:17:05 UTC-3, Luciano Pimenta escreveu:
Crie um método Remove e implemente a exclusão do item na sua lista (countryList)
Passe como parâmetro a posição do item no ListView.

Att


Em quarta-feira, 25 de fevereiro de 2015 22:00:07 UTC-3, ismael junior escreveu:
Boa noite Pessoal,

Estou com dúvidas no uso de listView e CheckBox, criei um customAdapter para ter uma lista com imagem, texto e checkbox.

Segue abaixo a tela do aplicativo:

Quando clico no Texto ou imagem vou para tela de alterar cadastro, Ao selecionar o checkbox gostaria de remover o produto da lista.

Estou com dúvida para implementar a remoção em meu customAdapter. Segue o código do customAdapter abaixo caso necessário posto outras informações.

Desde já agradeço qualquer informação, link de exemplos. 

Já pesquisei bastante inclusive aqui no grupo mas sem êxito. :(

Esse aplicativo é para aprendizado infelizmente travei nessa parte.

public class MyCustomAdapter extends ArrayAdapter<Country> {

    public ArrayList<Country> countryList;

    private Context context;


    public MyCustomAdapter(Context context, int textViewResourceId, ArrayList<Country> countryList) {

        super(context, textViewResourceId, countryList);

        this.context = context;

        this.countryList = new ArrayList<Country>();

        this.countryList.addAll(countryList);

    }


    private class ViewHolder {

        TextView code;

        CheckBox name;

    }

    @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) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = vi.inflate(R.layout.country_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 ;

                Country country = (Country) cb.getTag();

                Toast.makeText(context.getApplicationContext(),

                                        "Clicked on Checkbox: " + cb.getText() +

                        " is " + cb.isChecked(),

                        Toast.LENGTH_LONG).show();

                country.setSelected(cb.isChecked());

                }

                 });

        }else {

            holder = (ViewHolder) convertView.getTag();

        }

        Country country = countryList.get(position);

        holder.code.setText(" (" + country.getCode() + ")");

        holder.name.setText(country.getName());

        holder.name.setChecked(country.isSelected());

        holder.name.setTag(country);


        return convertView;

        }

    }

 


--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário