0

I have a grid view that I reuse a few times in an app. Separate activities drive what data appears. I would like to set different bg images for each activity.

What I would like to do is avoid creating multiple layouts by using viewgroup.layoutparams.

Currently, I have this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid_view);

But I would like to have something like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid_view, ViewGroup.LayoutParams.View_background(R.drawable.background1));

Only one issue: there is no View_background layout parm...

This is an RTM but I can't seem to find it. Anyone know what it is? Is there one?

John Stack
  • 618
  • 1
  • 4
  • 19

1 Answers1

3

You can not change background using LayoutParams. Instead, assign an ID to the root view in your XML file and use this code to change the background:
findViewById(R.id.your_view).setBackgroundResource(R.drawable.background1);

Grishka
  • 2,465
  • 1
  • 20
  • 38