You can make an independent button.xml file (or even make it like a style) and then inflate it in your code as needed.
, , , , . , , , , xml for.
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
String[] countries = {"US", "Canada", "UK", "Australia"};
String country;
LinearLayout buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout);
buttonLayout.removeAllViews();
for (int i = 0; i < countries.length(); i++) {
country = countries.getString(i);
Button temp = (Button)inflater.inflate(R.layout.button);
button.setId(id);
button.setText(country);
buttonLayout.addView(temp);
}
: XML include :
<include layout="@layout/button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
/>