How to create Button Dynamically in android?

后端 未结 5 900
抹茶落季
抹茶落季 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:37

    If you want to create dynamic view (like EditText,textview etc) then just use this code and run it in your application.

    MyActivity.java://your java file

     LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout1);
     EditText et = new EditText(v.getContext());
     et.setText("My new Edit Text);
     et.setMinLines(1);
     et.setMaxLines(3);
     ll.addView(et);
    

    In XML File:

     
    

提交回复
热议问题