Creating seekbar dynamically and giving listeners for that but it is not working properly Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Creating seekbar dynamically and giving listeners for that but it is not working properly without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am inflating the seekbar dynamically,but if i press the first seekbar, listener changing the values from last seek bar only .

for (int i = 0; i < controlList.size(); i++) {
            view1 = seekbar_inflate.inflate(R.layout.mysxm_control_coloumn, null, false);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            FrameLayout frame = (FrameLayout) view1
                    .findViewById(R.id.sliderLayout);
            vertical_seekbar=new VerticalSeekBar(MyApplication.getAppContext());
            vertical_seekbar.setId(i);
            final int id = vertical_seekbar.getId();
            vertical_seekbar.setProgressDrawable(getResources().getDrawable(R.drawable.sxm_selector_column));
            frame.addView(vertical_seekbar, params);
            vertical_seekbar=(VerticalSeekBar)view1.findViewById(id);
            equalizer_view.addView(view1);
            vertical_seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar,
                        int progress, boolean arg2) {


                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {


                }
            });
        }

how to give the listeners for each seek bar? pls suggest some answer

Answer

Just slight modification in my code,In this what i have realized android every widgets working based on id only.In this code you can differentiate the seekbar variable like vertical_seekbar and vertical_seekbar1 for me this the solution.Still this solution very strange for me.

for (int i = 0; i < controlList.size(); i++) {
                view1 = seekbar_inflate.inflate(R.layout.mysxm_control_coloumn, null, false);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                FrameLayout frame = (FrameLayout) view1
                        .findViewById(R.id.sliderLayout);
                vertical_seekbar=new VerticalSeekBar(MyApplication.getAppContext());
                vertical_seekbar.setId(i);
                final int id = vertical_seekbar.getId();
                vertical_seekbar.setProgressDrawable(getResources().getDrawable(R.drawable.sxm_selector_column));
                frame.addView(vertical_seekbar, params);
                vertical_seekbar1=(VerticalSeekBar)view1.findViewById(id);
                equalizer_view.addView(view1);
                vertical_seekbar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                    @Override
                    public void onProgressChanged(SeekBar seekBar,
                            int progress, boolean arg2) {


                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {

                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {


                    }
                });
            }
We are here to answer your question about Creating seekbar dynamically and giving listeners for that but it is not working properly - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji