mardi 19 juillet 2016

Create "Select all" button

i'm trying to create a button which will check/unchek all of the files in the listview. So far i've manager to create checkboxes for all of the files, but now i have to create a button that will check all of the items. I have used Metadata class in the listener for the checkboxes.

Here's my adapter:

 public class ResultsAdapter extends DataBufferAdapter<Metadata>{


        Context context;
         public ResultsAdapter(Context context) {
            super(context, R.layout.list_item);
    this.context = context;

        }



        private class ViewHolder {
            TextView txtView;
            CheckBox checkBox;
            CheckBox selectAllChk;


        }

        @Override
        public View getView(final int position, View convertView, final ViewGroup parent) {

            ViewHolder holder;


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

              holder = new ViewHolder();

                holder.txtView = (TextView) convertView.findViewById(R.id.textView1);
                holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
                holder.selectAllChk = (CheckBox) convertView.findViewById(R.id.selectAllButton);
                convertView.setTag(holder);

                final ViewHolder finalHolder = holder;


                holder.checkBox.setOnClickListener(new View.OnClickListener() {
                   /* private Context applicationContext;

                    public Context getApplicationContext() {
                        return applicationContext;
                    }*/

                    @Override
                    public void onClick(View v) {
    Metadata metadata = getItem(position);
                        finalHolder.txtView.setText(metadata.getTitle());
          }
                });
            } else {
                holder = (ViewHolder)convertView.getTag();

            }

            return convertView;
     }
    }




Aucun commentaire:

Enregistrer un commentaire