I have a frame layout and want to change the background image/color depending on the current state of an array. I can change text depending on the array so understand how to do that but can't find a way to reference the layout.
I've initialised the frame layout (li) after the on create however when I try change the colour in the later method I get the error "Non-static field 'li' can not be referenced from a static context".
Any help appreciated
public class GridViewFragmentActivity extends FragmentActivity
{
FrameLayout li;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout li =(FrameLayout) findViewById(R.id.framelayout);
final DotsPageIndicator mPageIndicator;
final GridViewPager mViewPager;
final String[][] data =
{
{ "Row 0, Col 0", "Row 0, Col 1", "Row 0, Col 2", "Row 0, Col 3" },
{ "Row 1, Col 0", "Row 1, Col 1", "Row 1, Col 2" },
{ "Row 2, Col 0", "Row 2, Col 1", "Row 2, Col 2" }
};
// Get UI references
mPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
mViewPager = (GridViewPager) findViewById(R.id.pager);
// Assigns an adapter to provide the content for this pager
mViewPager.setAdapter(new GridPagerAdapter(getFragmentManager(), data));
mPageIndicator.setPager(mViewPager);
}
private static final class GridPagerAdapter extends FragmentGridPagerAdapter {
String[][] mData;
private GridPagerAdapter(FragmentManager fm, String[][] data)
{
super(fm);
mData = data;
}
@Override
public Fragment getFragment(int row, int column)
{
String text = "CARD FRAGMENT";
if (row == 2 && column == 1)
{
text = "SIT UP";
li.setBackgroundColor(Color.parseColor("#FFFFFF"));
}
else
{
text = "PRESS UP";
li.setBackgroundColor(Color.parseColor("#FF0000"));
}
return (CardFragment.create(text, mData[row][column]));
}
@Override
public int getRowCount()
{
return mData.length;
}
@Override
public int getColumnCount(int row)
{
return mData[row].length;
}
}
}