【问题标题】:Looping through specific widgets循环遍历特定的小部件
【发布时间】:2019-07-11 08:56:48
【问题描述】:

假设我有一个表格布局,并且我有一个名为“添加人员”的按钮,每次单击它时都会动态添加一行,其中包含两个 EdiText。现在有另一个按钮应该将第一个 editText 值保存在数据库中,并添加(总和)第二个 editText 的所有值。在 HTML 中非常简单,我可以简单地将类属性添加到两个输入并循环遍历每个类名。但我不知道我应该如何在 android 中做到这一点。

【问题讨论】:

  • 假设你有一些代码要显示...
  • 使用回收站视图

标签: java android


【解决方案1】:

如何将参考文献保存在两个列表中?然后,您可以简单地遍历列表以将值存储在数据库中或对它们求和。

【讨论】:

    【解决方案2】:

    原答案check

        public void init(){
        TableLayout tablelayout = (TableLayout) findViewById(R.id.displayLinear);
    
    
        for (int i = 0; i <2; i++) {
    
           //Dynamic Button
           Button myButton = new Button(this);
           myButton.setText("Push Me");
    
           LinearLayout ll = (LinearLayout)findViewById(R.id.buttonlayout);
           LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,  
           LayoutParams.WRAP_CONTENT);
           ll.addView(myButton, lp);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多