Note that there are some explanatory texts on larger screens.

plurals
  1. POList items in Listfragment changes to system default background when scrolling the list?
    primarykey
    data
    text
    <p>I am first time asking question,please solve my problem. I am developing small Music player App. in that I've facing a silly problem,i searched on google a lot but still it is.</p> <p>I am using listfragment to show the list of songs.Now the problem is when i set list item background to transparent it works.But as soon as i scroll the list the list background changes to system default background.</p> <p>I am new to android,Please help me...</p> <p>I tried these already in my layout files:</p> <pre><code>android:background="@android:color/transparent" android:cacheColorHint="#00000000" </code></pre> <p>My main activity code is:</p> <pre><code> package com.android.player; import in.wptrafficanalyzer.viewpagerdemo.R; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewPager; import android.view.Menu; public class MainActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** Getting a reference to the ViewPager defined the layout file */ ViewPager pager = (ViewPager) findViewById(R.id.pager); /** Getting fragment manager */ FragmentManager fm = getSupportFragmentManager(); /** Instantiating FragmentPagerAdapter */ MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm); /** Setting the pagerAdapter to the pager object */ pager.setAdapter(pagerAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>/<strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>***</strong> Here is my code for SongsList.java:-</p> <pre><code> package com.android.player; import in.wptrafficanalyzer.viewpagerdemo.R; import java.io.FileDescriptor; import java.math.BigDecimal; import android.content.ContentUris; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.support.v4.app.ListFragment; import android.support.v4.widget.SimpleCursorAdapter; import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class SongsList extends ListFragment{ int mCurrentPage; private MediaCursorAdapter mediaAdapter = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** Getting the arguments to the Bundle object */ Bundle data = getArguments(); /** Getting integer data of the key current_page from the bundle */ mCurrentPage = data.getInt("current_page", 0); String sortOrder = MediaStore.MediaColumns.DISPLAY_NAME + " ASC"; Cursor cursor = getActivity().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null,null,null,sortOrder); if(null != cursor) { mediaAdapter = new MediaCursorAdapter(getActivity(), R.layout.listitem, cursor); setListAdapter(mediaAdapter); } } public Bitmap getAlbumart(Long album_id) { Bitmap bm = null; try { final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart"); //album_id = ()album_id; Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id); ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r"); if (pfd != null) { FileDescriptor fd = pfd.getFileDescriptor(); bm = BitmapFactory.decodeFileDescriptor(fd); } } catch (Exception e) { } return bm; } public class MediaCursorAdapter extends SimpleCursorAdapter{ @SuppressWarnings("deprecation") public MediaCursorAdapter(Context context, int layout, Cursor c) { super(context, layout, c,new String[] { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.TITLE, MediaStore.Audio.AudioColumns.DURATION}, new int[] { R.id.displayname, R.id.title, R.id.duration }); } @Override public void bindView(View view, Context context, Cursor cursor) { TextView title = (TextView)view.findViewById(R.id.title); TextView name = (TextView)view.findViewById(R.id.displayname); TextView duration = (TextView)view.findViewById(R.id.duration); ImageView imageView1 = (ImageView)view.findViewById(R.id.imageView1); Bitmap bm = getAlbumart(cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.ALBUM_ID))); if(bm!=null) { imageView1.setImageBitmap(bm); } else { imageView1.setImageResource(R.drawable.ic_launcher); } name.setText(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME))); title.setText(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE))); long durationInMs = Long.parseLong(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION))); int seconds = (int) (durationInMs / 1000) % 60 ; int minutes = (int) ((durationInMs / (1000*60)) % 60); int hours = (int) ((durationInMs / (1000*60*60)) % 24); double durationInMin = ((double)durationInMs/1000.0)/60.0; String durationTxt = ""; if(hours==0) { if(minutes&lt;10) { durationTxt = "0"+minutes+":"+seconds; } else { durationTxt = minutes+":"+seconds; } } else { durationTxt = hours+":"+"0"+minutes+":"+seconds; } durationInMin = new BigDecimal(Double.toString(durationInMin)).setScale(2, BigDecimal.ROUND_UP).doubleValue(); duration.setText(durationTxt); view.setTag(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))); } } public void onActivityCreated(View view, Bundle savedInstanceState) { getListView().setCacheColorHint(android.R.color.transparent); super.onViewCreated(view, savedInstanceState); } } </code></pre> <p>/<strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**</strong></p> <p>Here are activity_mail.xml:</p> <pre><code>&lt;RelativeLayout 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" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/sparkle"&gt; &lt;android.support.v4.view.PagerTitleStrip android:id="@+id/pager_title_strip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:textColor="#fff" android:paddingTop="4dp" android:paddingBottom="4dp" /&gt; &lt;/android.support.v4.view.ViewPager&gt; &lt;/RelativeLayout&gt; </code></pre> <p>/<strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong> Here is listitem.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:cacheColorHint="#00000000" android:orientation="horizontal" android:padding="5dip" android:id="@+id/list_item" &gt; &lt;!-- ListRow Left sied Thumbnail image --&gt; &lt;LinearLayout android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:layout_alignParentLeft="true" android:background="@drawable/transparent_bg" android:cacheColorHint="#00000000" android:layout_marginRight="5dip"&gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="60dip" android:layout_height="60dip" android:src="@drawable/ic_launcher"/&gt; &lt;/LinearLayout&gt; &lt;!-- Title Of Song--&gt; &lt;TextView android:id="@+id/displayname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/thumbnail" android:layout_toRightOf="@+id/thumbnail" android:textColor="#fff" android:typeface="sans" android:textSize="15dip" android:textStyle="bold"/&gt; &lt;!-- Artist Name --&gt; &lt;TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/displayname" android:textColor="#fff" android:textSize="10dip" android:layout_marginTop="1dip" android:layout_toRightOf="@+id/thumbnail" android:singleLine="true" /&gt; &lt;!-- Rightend Duration --&gt; &lt;TextView android:id="@+id/duration" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/displayname" android:gravity="right" android:layout_marginRight="5dip" android:textSize="12dip" android:textColor="#fff" android:textStyle="bold"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Please have a look at it and help me. thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload