Android код в Java как добавить текст в кнопку во время выполнения. Я добавляю весь код android java code и XML.
private ViewGroup viewGroup;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutTransition layoutTransition = new LayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGE_APPEARING);
viewGroup = (ViewGroup) findViewById(R.id.container);
viewGroup.setLayoutTransition(layoutTransition);
}
public void onClick(View view) {
viewGroup.addView(new Button(this));
}
xml код
это XML код .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:onClick="onClick"
android:text="Button" />
</LinearLayout>