如何在片段中动态添加TableRow? [英] How to dynamically add a TableRow in a Fragment?
本文介绍了如何在片段中动态添加TableRow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public View onCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState){
查看视图= 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);
返回视图;
}
提前谢谢。
解决方案
你必须给出view.findViewById,
,因为你在视图中添加了。
TableLayout ll =(TableLayout)view.findViewById(R.id.tableLayout1);
检查这篇文章,它肯定会帮助你。
I am new in Android programming, currently I 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;
}
Thank you in advance.
解决方案
you have to give view.findViewById, because you are adding that in the view.
TableLayout ll = (TableLayout) view.findViewById(R.id.tableLayout1);
Check this post. it will surely help you.
这篇关于如何在片段中动态添加TableRow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文