本文介绍了如何在片段添加tablerow的动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的编程其实我试图在片段动态插入表格的布局里面一个TextView。它的工作,而类扩展到活动。下面是我的code片段。我失去了一些东西。

I am new in android programming actually am trying to insert a textview inside the table layout dynamically in fragment. It worked while extending the class to Activity. Below is my code snippet. Am I missing something.

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_schedule, null);

    TableLayout ll = (TableLayout) getActivity().findViewById(R.id.tableLayout1);
     TableRow tr= new TableRow(getActivity());
     TextView tv1 = new TextView(getActivity());
    tv1.setText("TEST NUMBER");
    tv1.setTextColor(Color.WHITE);
    tv1.setTextSize(20);
    tv1.setPadding(5, 5, 5, 5);
    tr.addView(tv1);
    ll.addView(tr);
    return view;
}

感谢您在adbance

Thank you in adbance

推荐答案

你必须给view.findViewById,
因为要添加在视图中。

you have to give view.findViewById,because you are adding that in the view.

TableLayout ll = (TableLayout) view.findViewById(R.id.tableLayout1);

后。它一定会帮助你。

这篇关于如何在片段添加tablerow的动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:54