daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

SwipeLayout as ListView item: SeekBar updating multiple time with recycled child views #151

Open ralphilius opened 9 years ago

ralphilius commented 9 years ago

Hello,

I am using this project in my new app which shows a list of tracks with a play button and a SeekBar progress. I am able to get the tracks playing but I got an issue with updating the SeekBar.

Any suggestion to how I could get it updated properly?

child_item.xml

<com.daimajia.swipe.SwipeLayout
    xmlns:swipe="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    swipe:leftEdgeSwipeOffset="0dp"
    swipe:rightEdgeSwipeOffset="0dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#FF5534"
        android:gravity="center"
        android:tag="Bottom3"
        android:weightSum="10">
        <ImageView
            android:id="@+id/trash"
            android:layout_width="27dp"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:src="@drawable/trash" />
        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="4"
            android:background="@drawable/white"
            android:text="Yes,Delete"
            android:textColor="#FF5534" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/item_selector"
        android:padding="10dp">

        <ImageButton
            android:id="@+id/buttonPlayPause"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:onClick="playpause" />
        <TextView
            android:id="@+id/songName"
            android:layout_width="wrap_content"
            android:layout_toRightOf="@id/buttonPlayPause"
            android:layout_height="wrap_content"
            />
        <SeekBar
            android:id="@+id/progressBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/buttonPlayPause"
            android:layout_below="@id/songName"/>
    </RelativeLayout>
</com.daimajia.swipe.SwipeLayout>

ListViewAdapter.java

@Override
    public void fillValues(int position, View convertView) {
        ImageButton imageButton = (ImageButton) convertView.findViewById(R.id.buttonPlayPause);
        TextView t = (TextView)convertView.findViewById(R.id.songName);
        SeekBar seekbar = (SeekBar) convertView.findViewById(R.id.progressBar);
        String url = adapterData[position];
        MediaPlayer mp = mpUtils.getMediaPlayer(url);
        imageButton.setTag(R.id.TAG_MEDIAPLAYER, mp);
        imageButton.setBackgroundResource(R.drawable.ic_media_play);
        Runnable updateProgress = new UpdateSongTime(mp,seekbar);

        imageButton.setOnClickListener(new playButtonClicked(position,updateProgress));
        t.setText((position + 1) + ".");
}
private class UpdateSongTime implements Runnable {
        MediaPlayer mediaPlayer;
        SeekBar seekBar;
        double startTime = 0;
        public UpdateSongTime(MediaPlayer mp, SeekBar sb){
            this.mediaPlayer = mp;
            this.seekBar = sb;
        }
        public void run() {
            startTime = mediaPlayer.getCurrentPosition();

            seekBar.setProgress((int)startTime);
            myHandler.postDelayed(this, 100);
        }
    };
obaidjatoi commented 8 years ago

Have you got any solution ?? :p if yes then please help me , i am facing this issues from many days !

mahendraleo4 commented 8 years ago

Have you got any solution ??

ralphilius commented 8 years ago

Nope. I switched to use BottomSheet instead of SwipeLayout and I have a universal SeekBar in the main layout, not in child's xml.

mahendraleo4 commented 8 years ago

Can you show me your adapter class code?Please

Shubhampatni86 commented 7 years ago

You need to keep track id in your data class and that you should use inside onBindViewHolder(..) before to update UI. Other than this I observed another issue, 1) I'm notifying item with (~100ms) interval and so it does not allow user to scroll down(Up work as expected.) 2) For last 3 item you can observe it's pushing list at bottom and it follow issue #1.

Please update if you also face same.