ChangeBackground of TableLayout when i click on a button on the same layout
i have created a linearlayout having 2 table layouts.in the 1st table i have button .now i want to change the 2dn table layout background when i click on the button.not 开发者_JS百科the whole layout ,only the 2nd tablelayout background will be changed. please help me with some sample code.
In your onCreate()
method you need to add a listener to the button and in that listener you can retrieve the view (table layout) and modify its properties. To find the button and the view you're changing you'll need to specify IDs for them in the XML (assuming you're inflating it from XML). Try something like this (untested) code:
Button button = (Button) findViewById(R.id.mybutton);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(final View view)
{
TableLayout tableLayout = (TableLayout) findViewById(R.id.mytablelayout);
tableLayout.setBackgroundResource(R.drawable.mybackgroundimage);
}
});
精彩评论