Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.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
Java android表中每个单元格的唯一id_Java_Android - Fatal编程技术网

Java android表中每个单元格的唯一id

Java android表中每个单元格的唯一id,java,android,Java,Android,我有一个android表,其中按钮作为表元素。我想为每个单元格(按钮)分配一个唯一的id,这样当我单击特定单元格(按钮)时,它应该返回相应的id。请帮助我如何执行此操作。样本代码将是伟大的。谢谢。在xml中使用 android:id ="@+id/your_id" 或以编程方式 yourelement.setId(yourID); 范例 button.setId(01); 其中button是button类的对象如果在xml中有硬编码的按钮,则在xml中设置id,如下所示:

我有一个android表,其中按钮作为表元素。我想为每个单元格(按钮)分配一个唯一的id,这样当我单击特定单元格(按钮)时,它应该返回相应的id。请帮助我如何执行此操作。样本代码将是伟大的。谢谢。

在xml中使用

 android:id ="@+id/your_id"
或以编程方式

yourelement.setId(yourID);
范例

  button.setId(01);

其中button是button类的对象

如果在xml中有硬编码的按钮,则在xml中设置id,如下所示:

     <Button
        android:id="@+id/btn_row_col"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="button1"
        />

只需在按钮中添加一个
android:id=“@+id/unique_id_x_y”
,x和y分别是列号和行号,为什么不使用标记来存储该视图的唯一信息呢。这比创建要查看的唯一id更好。
 Button newBtn=new Button();
   newBtn.setText("button");
   newBtn.setId(yourId);  //here setid to your button