Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:01:51+00:00 2026-06-17T06:01:51+00:00

I am first time asking question,please solve my problem. I am developing small Music

  • 0

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.

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.

I am new to android,Please help me…

I tried these already in my layout files:

android:background="@android:color/transparent"
android:cacheColorHint="#00000000"

My main activity code is:

    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;
    }
}

/*******************************
Here is my code for SongsList.java:-

    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<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);
    }

}

/***************************

Here are activity_mail.xml:

<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" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/sparkle">

        <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" />

    </android.support.v4.view.ViewPager>

</RelativeLayout>

/*****************************
Here is listitem.xml:

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <!--  ListRow Left sied Thumbnail image -->
    <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">

        <ImageView
             android:id="@+id/imageView1"
            android:layout_width="60dip"
            android:layout_height="60dip"
            android:src="@drawable/ic_launcher"/>

    </LinearLayout>

    <!-- Title Of Song-->
    <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"/>

    <!-- Artist Name -->
    <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" />

    <!-- Rightend Duration -->
    <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"/>


</RelativeLayout>

Please have a look at it and help me.
thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:01:53+00:00Added an answer on June 17, 2026 at 6:01 am

    android:cacheColorHint is really the solution, but you have put it in the wrong place.
    It is an attribute of ListView, not of list item.

    This should work well:

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000" />
    

    UPDATED:

    I just looked at your code one more time and found this line:

    getListView().setCacheColorHint(android.R.color.transparent);
    

    It’s wrong because android.R.color.transparent just a reference but not a real color value.

    Also, there is no onActivityCreated(View view, Bundle savedInstanceState) method in ListFragment. This is onActivityCreated(Bundle savedInstanceState) actually. Try to replace it with the following code and it should work well.

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);  
        getListView().setCacheColorHint(Color.TRANSPARENT);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time asking a question, please be gentle! I have a
I'm sorry that was my first time for asking question in stackoverflow. I just
First time asking a question...Appreciate your kindness :-) I wrote a web service that
This my first time asking a question so please go easy one me :-p
This is my first time asking a question in this website so please bear
this is my first time asking a question here. I tried to be well
this is my first time asking a question so bear with me. I am
this is my first time asking a question on stackoverflow. I'm working on a
This is my first time asking a question on here. It has been very
This is my first time asking my question at stackoverflow. I'm working on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.