0

I am working with a MediaBrowserServiceCompat in my Android app and using a Handler to control the UI. I have implemented a Runnable that updates a TextView and a SeekBar every 200 milliseconds, and I am using a callback from the MediaBrowserServiceCompat to control the Handler. The TextView is a class variable that is getting set in onBindViewHolder by a click.

However, I am facing an issue where the RecyclerView is scrolling up when the TextView is getting updated. I have tried using RecyclerView.scrollToPosition() and RecyclerView.smoothScrollToPosition() to explicitly scroll to the item I want to display in the RecyclerView, but it doesn't seem to work. Is there any way to prevent the RecyclerView from scrolling up when the TextView is getting updated?

this is my code

Handler handler = new Handler();
Runnable updateProgress = new Runnable() {
    @Override
    public void run() {
        handler.postDelayed(this, 200);
        longProgress = MediaControllerCompat.getMediaController(ChatActivity.this).getPlaybackState().getPosition();
        Log.v("longProgress", String.valueOf(longProgress));
        seekBar.setProgress((int) longProgress);
        textView.setText((Utils.formatLongMilliSeconds(longProgress)));}

};

and I am using a callback from the MediaBrowserServiceCompat to contlor the handler like this

 if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
        handler.post(updateProgress);
    } else if (state.getState() != PlaybackStateCompat.STATE_PAUSED){
        handler.removeCallbacks(updateProgress);
}

The Text View is a claas variable is getting set in onBindViewHolder by the click like this

            root.binding.playChat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                textView = root.binding.textView40;

but when the text view is getting updated the recyclerview is scrolling up. how can i provent from happening this?

any help please?

0 Answers0