Use single xml layout for multiple activities with different datas

前端 未结 2 1734
轻奢々
轻奢々 2020-12-19 01:21

I know this is a very basic question, however as a newbie i cant get to work around it. So, I want to have multiple activities to use same the xml layout(consist for example

2条回答
  •  一生所求
    2020-12-19 01:53

    You can share the same layout file and the set the attributes for views in the onCreate(..) method of each activity.

    If you want a different URL to open for each image button you could set it at runtime as follows

    public void onCreate(Bundle b) {
    
        Button button =(Button)findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                //different action for each activity
            }
        });
    }
    

提交回复
热议问题