mardi 19 juillet 2016

Get Value out Specific Item inside BaseAdapter with a button that is outside of BaseAdapter

Hello I have the below BaseAdapter attached to a listview that is dynamically creating layouts. I need to pull values of items within these layouts by using a button that is not within the listview/BaseAdapter.

final ListView listView = (ListView) findViewById(R.id.listView2);
    final Global i = Global.getInstance();
    final BaseAdapter myAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return i.getcounter();
        }

        @Override
        public Boolean getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @SuppressLint("ViewHolder")
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.interrupt_view, parent, false);

            final CheckBox interruptor = (CheckBox) convertView.findViewById(R.id.interruptorCB);
            final CheckBox interrupted = (CheckBox) convertView.findViewById(R.id.interruptedCB);

            interruptor.setText(i.initialList().get(position));
            interrupted.setText(i.initialList().get(position));
            return convertView;
        }
    };
    listView.setAdapter(myAdapter);

    final Button saveInterBtn = (Button) findViewById(R.id.saveInterrupt);
    saveInterBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        for(int p = 0; p<i.getcounter();p++){

            //Here
        }

        }
    });

}

My code needs to pull the boolean value of a Checkbox using a "isClicked" and store it in an array when the saveInterBtn Button is clicked (which is outside of the ListView). I only know how to access each specific layout when inside of the BaseAdapter. I need help on how to access a specific Layout from outside of the BaseAdapter.

If you need more clarification, just let me know.

Thanks!!




Aucun commentaire:

Enregistrer un commentaire