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