【问题标题】:Adding Item in row in tablelayout android?在tablelayout android中的行中添加项目?
【发布时间】:2015-06-18 21:47:12
【问题描述】:

我想使用 for Order in Restaurant 或类似的东西在 Android 中创建一个具有 Table Layout 的应用程序。

示例:我有三列和行是动态的(取决于数据记录)。 在一条记录中,我有一些值,例如时间、信息、数字……所以,我可以用一条记录自定义 Framelayout。我如何将该视图添加到表的行中。我研究并只是看到添加新行但没有将新视图添加到一行的方法。如果 T 有 7 条记录。我该怎么做?

任何帮助将不胜感激!谢谢!

【问题讨论】:

  • 如果你减去我的问题,请告诉我为什么,我只是想知道,因为我是新手。

标签: android android-layout tablelayout


【解决方案1】:

也许这对人有帮助

TableLayout tl=(TableLayout)findViewById(R.id.maintable); 
TableRow tr1 = new TableRow(this); 
tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
TextView textview = new TextView(this); 
textview.setText(data); 
textview.setTextColor(Color.YELLOW); 
tr1.addView(textview); 
tl.addView(tr1, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

在表格布局中添加行的方式可以将多个TableRow 实例添加到您的tableLayout 对象中

tl.addView(row1); 
tl.addView(row2);

等等……

【讨论】:

  • 感谢您的回复,我之前看到很多这样的主题并且已经添加了新行但没有添加新项目。我的目的是,如果我的系统在我单击按钮添加时有 4 个项目,系统将在第 2 行添加新项目和第 5 个位置。不创建新行。
猜你喜欢
  • 2014-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-07
相关资源
最近更新 更多