mardi 19 mai 2020

SparseBooleanArray checked is always return 0

In my application there is a listvew in the fragment and it is connected with a adapter.In adapter iam using multidimensional array to pass values. on clicking the submit button in the fragment i getting checked value always 0

        mListView = root.findViewById(R.id.listView);
        mListView.setLongClickable(true);
        mListView.invalidateViews();
        mListView.getFirstVisiblePosition();
        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

  ItemSelectAdapter mItemSelectAdapter = new ItemSelectAdapter(getContext(), listcatDb.GetItemQRY();
    mListView.setAdapter(mItemSelectAdapter);

    mSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SparseBooleanArray checked = mListView.getCheckedItemPositions();
            int len = mListView.getAdapter().getCount();

            if(len!=0) {
                for (int i=0; i<checked.size(); i++) {
                        if (checked.valueAt(i)) {
                            String item = mListView.getAdapter().getItem(
                                    checked.keyAt(i)).toString();
                            Log.i(TAG,checked.get(i) + " was selected");

                        }
                    }
            }
        }
    });

In adapter

   String[][] sItemNameArray -> from listview

and setting checkbox

   holder.mItemCheckSelect.setTag(position);

        holder.mItemCheckSelect.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            //is chkIos checked?
            if (((CheckBox) v).isChecked()) {
                   mSelectQty.setText("0");

            }
        });



Aucun commentaire:

Enregistrer un commentaire