Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int previousPosition = -1;
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- ImageView image;
- if (previousPosition == position) {
- image = v.findViewById(R.id.btnPlay);
- image.setImageResource(R.drawable.ic_btn_play);
- previousPosition = -1;
- } else {
- image = v.findViewById(R.id.btnPlay);
- image.setImageResource(R.drawable.ic_btn_pause);
- previousPosition = position;
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <ListView
- android:id="@id/android:list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:listitem="@layout/fragment_item"
- android:choiceMode="singleChoice"
- android:background="@color/bg_listView"
- android:listSelector="@drawable/item_bg"/>
- <TextView
- android:id="@id/android:empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/no_data" />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <TableRow
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <ImageView
- android:id="@+id/btnPlay"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:srcCompat="@drawable/ic_btn_play"
- android:background="@null"
- android:contentDescription="@string/contentDescriptionPlay"
- android:layout_marginStart="8dp"
- android:layout_marginLeft="8dp"
- android:layout_marginTop="12dp" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tvSong"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/song"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="5dp"
- android:textSize="17sp"/>
- <TextView
- android:id="@+id/tvSinger"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/singer"
- android:layout_marginLeft="8dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="3dp"
- android:layout_marginBottom="8dp"/>
- </LinearLayout>
- </TableRow>
- <TextView
- android:id="@+id/tvDuration"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="end"
- android:text="@string/duration"
- android:textAlignment="viewEnd"
- android:layout_marginEnd="8dp"
- android:layout_marginRight="8dp"
- android:layout_marginTop="17dp"/>
- </FrameLayout>
Add Comment
Please, Sign In to add comment