2016-11-13 5 views
0

Я пытаюсь создать новую строку таблицы и добавить ее в существующий 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> 

ответ

0

добавить эту строку после tableLayout.addView (TableRow); Линия

getWindow().getDecorView().findViewById(android.R.id.content).invalidate(); 

обновить TableView вновь добавленный ряд будет виден

+0

Не похоже на работу. Я использую фрагмент, поэтому я написал то же самое, но с getActivity() перед ним – Medivh

+0

покажите свой код, что вы написали, для проверки – siddhesh

+0

Я добавил его непосредственно после tableLayout.getView (tableRow): getActivity(). GetWindow(). . getDecorView() findViewById (android.R.id.content) .invalidate(); – Medivh

Смежные вопросы