Guest User

Untitled

a guest
Nov 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. private int previousPosition = -1;
  2.  
  3. @Override
  4. public void onListItemClick(ListView l, View v, int position, long id) {
  5. super.onListItemClick(l, v, position, id);
  6.  
  7. ImageView image;
  8.  
  9. if (previousPosition == position) {
  10. image = v.findViewById(R.id.btnPlay);
  11. image.setImageResource(R.drawable.ic_btn_play);
  12. previousPosition = -1;
  13. } else {
  14. image = v.findViewById(R.id.btnPlay);
  15. image.setImageResource(R.drawable.ic_btn_pause);
  16. previousPosition = position;
  17. }
  18.  
  19. }
  20.  
  21. <?xml version="1.0" encoding="utf-8"?>
  22. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  23. xmlns:tools="http://schemas.android.com/tools"
  24. android:layout_width="match_parent"
  25. android:layout_height="match_parent"
  26. android:orientation="vertical">
  27.  
  28. <ListView
  29. android:id="@id/android:list"
  30. android:layout_width="match_parent"
  31. android:layout_height="match_parent"
  32. tools:listitem="@layout/fragment_item"
  33. android:choiceMode="singleChoice"
  34. android:background="@color/bg_listView"
  35. android:listSelector="@drawable/item_bg"/>
  36.  
  37. <TextView
  38. android:id="@id/android:empty"
  39. android:layout_width="match_parent"
  40. android:layout_height="match_parent"
  41. android:text="@string/no_data" />
  42. </LinearLayout>
  43.  
  44. <?xml version="1.0" encoding="utf-8"?>
  45. <FrameLayout
  46. android:layout_width="match_parent"
  47. android:layout_height="wrap_content"
  48. xmlns:app="http://schemas.android.com/apk/res-auto"
  49. xmlns:android="http://schemas.android.com/apk/res/android">
  50.  
  51. <TableRow
  52. android:layout_width="match_parent"
  53. android:layout_height="wrap_content">
  54.  
  55. <ImageView
  56. android:id="@+id/btnPlay"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. app:srcCompat="@drawable/ic_btn_play"
  60. android:background="@null"
  61. android:contentDescription="@string/contentDescriptionPlay"
  62. android:layout_marginStart="8dp"
  63. android:layout_marginLeft="8dp"
  64. android:layout_marginTop="12dp" />
  65.  
  66. <LinearLayout
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:orientation="vertical">
  70.  
  71. <TextView
  72. android:id="@+id/tvSong"
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:text="@string/song"
  76. android:layout_marginLeft="8dp"
  77. android:layout_marginStart="8dp"
  78. android:layout_marginTop="5dp"
  79. android:textSize="17sp"/>
  80.  
  81. <TextView
  82. android:id="@+id/tvSinger"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:text="@string/singer"
  86. android:layout_marginLeft="8dp"
  87. android:layout_marginStart="8dp"
  88. android:layout_marginTop="3dp"
  89. android:layout_marginBottom="8dp"/>
  90. </LinearLayout>
  91. </TableRow>
  92.  
  93. <TextView
  94. android:id="@+id/tvDuration"
  95. android:layout_width="match_parent"
  96. android:layout_height="wrap_content"
  97. android:layout_gravity="end"
  98. android:text="@string/duration"
  99. android:textAlignment="viewEnd"
  100. android:layout_marginEnd="8dp"
  101. android:layout_marginRight="8dp"
  102. android:layout_marginTop="17dp"/>
  103. </FrameLayout>
Add Comment
Please, Sign In to add comment