Я пытаюсь создать новую строку таблицы и добавить ее в существующий TableLayout. Я просмотрел Интернет, и кажется, что я пробовал все, но я не могу показать новую строку. Если я добавлю TableRow с идентификатором в макете и добавлю свой собственный ImageView к нему, не добавляя новый TableRow в макет, который будет показан в ImageView, но мне нужно добавить новую строку динамически. В моем фрагменте:Как добавить TableRows динамически?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_default_view,
container, false);
final ViewGroup tableLayout = (ViewGroup) rootView.findViewById
(R.id.table_bracket);
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT
);
TableRow tableRow = new TableRow(context);
tableRow.setLayoutParams(layoutParams);
SeparatorImageView separator = new SeparatorImageView(getActivity());
separator.setLayoutParams(layoutParams);
tableRow.addView(separator);
tableLayout.addView(tableRow);
return rootView;
}
вот раскладка я пытаюсь добавить:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mbusby.bracketsandbox.DefaultViewFragment">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table_bracket"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
</TableLayout>
Не похоже на работу. Я использую фрагмент, поэтому я написал то же самое, но с getActivity() перед ним – Medivh
покажите свой код, что вы написали, для проверки – siddhesh
Я добавил его непосредственно после tableLayout.getView (tableRow): getActivity(). GetWindow(). . getDecorView() findViewById (android.R.id.content) .invalidate(); – Medivh