Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何找到动态创建的按钮?安卓_Android_Button_Dynamic_Find - Fatal编程技术网

Android 如何找到动态创建的按钮?安卓

Android 如何找到动态创建的按钮?安卓,android,button,dynamic,find,Android,Button,Dynamic,Find,我已使用以下代码在类中动态创建了一些按钮: 变量drawView.getNumeroMallas()每次都可能不同 for(int i=0;i<drawView.getNumeroMallas();i++){ Button buttonMalla = new Button(this); buttonMalla.setText("Malla "+(i+1)); buttonMalla.setI

我已使用以下代码在类中动态创建了一些按钮: 变量drawView.getNumeroMallas()每次都可能不同

     for(int i=0;i<drawView.getNumeroMallas();i++){

                Button buttonMalla = new Button(this);
                buttonMalla.setText("Malla "+(i+1));
            buttonMalla.setId(i+1);
                buttonMalla.setTag(Boolean.FALSE);
}
for(int i=0;i
  • 您可以将它们存储在列表中,然后使用getter方法从代码的另一部分访问此列表

  • 您不应该像这样使用
    setId()
    ,因为您的ID实际上会与其他ID发生冲突,所以您应该使用
    View.generateWid()


  • 将按钮发送到另一个类,id的存储方式与在XML中创建id时不同。如何将按钮发送到另一个类?在类中创建一个公共方法,并为其提供
    View.generateViewId()
    仅在SDK 17及以上版本中可用,您还需要使用吗that@tyczj不,我不会在这种情况下使用它。我建议使用phantomlimb在此解决方案中列出的密钥生成方法:@zgc7009抱歉,这不是一个问题,有一个输入错误。
    你还必须使用它吗
    假设是
    ,所以你仍然需要e使用该