How to create Button Dynamically in android?

后端 未结 5 913
抹茶落季
抹茶落季 2020-11-30 05:02

\"Links\"

I want to create a page like this. these 7 buttons are already exist but if user want to add more cat

5条回答
  •  无人及你
    2020-11-30 05:31

    LinearLayout mainLayout = (LinearLayout)findViewById(R.id.yourlayoutidthatisonethepicture);
    
    Button addButton =new Button(this);
    addButton.setText("add");
    
    mainLayout.addView(addButton);
    

    to remove is the same just change this "mainLayout.addView(addButton)" to removeView or setVisibility of button to View.GONE

提交回复
热议问题