0

I am writing an custom list, in which displayed 3rd list item has toggle button as an child. On toggle button click it launch an confirmation dialog, if wants toggle button or not.

Now if list not scrolled then it work perfect. But if scroll list(so 3rd displayed as 1st item) then button toggle state(for toggleButton.setChecked(false)) not working after Dialog-Cancel action.

Any suggestion if I am missing anything.

EDIT

public View getView(int position, View convertView, ViewGroup parent) {
            View vi = convertView;

            if(convertView == null) {
                vi = inflater.inflate(R.layout.setting_prefernce_row, parent, false);
                final ViewHolder viewHolder = new ViewHolder();

                viewHolder.title = (TextView)vi.findViewById(R.id.txtPreferenceName); // Preference Name
                viewHolder.txtPreferenceSub = (TextView)vi.findViewById(R.id.txtPreferenceSub); // Sub-Preference Name

                viewHolder.txtArrow = (TextView)vi.findViewById(R.id.txtArrow); // text before arrow
                viewHolder.imgArrow = (ImageView)vi.findViewById(R.id.imgArrow); // right_arrow

                viewHolder.btnToggleState = (ToggleButton)vi.findViewById(R.id.tglToggleState); // toggle button
                viewHolder.switchTemperatureUnit = (ImageView)vi.findViewById(R.id.switchTemperatureUnit); // switch button for temperature

                //viewHolder.checkbox.setTag(list.get(position));
                //viewHolder.scores.setTag(list.get(position));
                vi.setTag(viewHolder);
            } else {
                vi = convertView;
            }

....

}
Piyush
  • 18,895
  • 5
  • 32
  • 63
CoDe
  • 11,056
  • 14
  • 90
  • 197

2 Answers2

0
  1. After vi retrive via covertviiew .gettag and retrieve checkbox object
  2. Set the check box visibility to Gone (This code should run always)
  3. Check if row is 3 (as you want) and make the visibility change
  4. if toggle is visible the update the state based on model data
  5. When ever toggle is changed update the model

These are the usual things that we need to do for this type specific requirement. If you didn't get the issue resolved let me know.

Ganesh Kanna
  • 2,269
  • 1
  • 19
  • 29
0

To optimize ViewHolder implementation damm required. And to get target item view following worked great.

for(int i = start, j = lstSettingPreference.getLastVisiblePosition(); i <= j; i++) {
                if (ordinal == (int) lstSettingPreference.getItemAtPosition(i)) {
                    view = lstSettingPreference.getChildAt(i - start);
                    lstSettingPreference.getAdapter().getView(i, view, lstSettingPreference);
                    break;
                }
            }

Reference link: https://stackoverflow.com/a/9987616/2624806.

Community
  • 1
  • 1
CoDe
  • 11,056
  • 14
  • 90
  • 197