Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background color of list become white in scrolling when using android.support.v4.app.ListFragment;

I'm facing a critical problem. I'm trying to change background color (transparent) of list in scrolling time but unable to do it. I tried to change is by xml of listView as well as by code too. but in both condition list background become white. I'm using android.support.v4.app.ListFragment; and FragmentPagerAdapter.

I wanna change list scroll time color change. for this i'm using following code.

public static class ArrayListFragment extends ListFragment {
    int mNum;
    /**
     * Create a new instance of CountingFragment, providing "num"
     * as an argument.
     */
    static ArrayListFragment newInstance(int num) {
        ArrayListFragment f = new ArrayListFragment();
        // Supply num input as an argument.
        Bundle args = new Bundle();
        args.putInt("num", num);
        f.setArguments(args);

        return f;
    }
    /**
     * When creating, retrieve this instance's number from its arguments.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mNum = getArguments() != null ? getArguments().getInt("num") : 1;
    }

    /**
     * The Fragment's UI is just a simple text view showing its
     * instance number.
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
        //v.setBackgroundResource(R.drawable.background);
        View tv = v.findViewById(R.id.text);

        ((TextView)tv).setText(frameName());


        return v;
    }

   // @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_checked, RishavArraylist() ));

    }

Please tell me how i can change background of scrolling list at run time?? Thank you.

like image 881
Rvg.2ky Avatar asked Jul 25 '12 13:07

Rvg.2ky


2 Answers

Take a look at this blog post from Google in particular the portion of XML pertaining to;

    android:cacheColorHint="#00000000"
like image 76
BrantApps Avatar answered Nov 10 '22 21:11

BrantApps


We have plenty of options for this problem, you can set the background as transparent through programming like

yourlistview.setCacheColorHint(Color.TRANSPARENT); 

or through xml

android:cacheColorHint="@android:color/transparent"
like image 20
Sampath Kumar Avatar answered Nov 10 '22 21:11

Sampath Kumar