开发者

ChangeBackground of TableLayout when i click on a button on the same layout

开发者 https://www.devze.com 2023-03-05 21:14 出处:网络
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 ,

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号