android view.getid,android view.getId() returns -1

在尝试为数据表格中的表头单元格获取并存储视图ID时,遇到了问题。代码中当试图从刚加载的视图中获取ID时,总是返回-1,即NO_ID。尽管在调试过程中可以看到视图ID已经分配并且可见,例如一个LinearLayout的ID为830042440680。这个问题阻碍了后续通过ID来标识特定单元格视图的操作。
摘要由CSDN通过智能技术生成

I need to change the text for a range of header cells in the data table.

In order to achieve that, I would need to retrieve and store the view ids assigned to those cells, so they can be used later to identify those cell views.

However, when I try to get an ID for the just inflated cell view, it always returns -1.

Here is my sample code:

@Override

public View getView(final int row, final int column, View converView, ViewGroup parent) {

if (converView == null) {

converView = inflater.inflate(getLayoutResource(row, column), parent, false);

if (row == -1){

int viewId = converView.getId();

setHeaderId(viewId, column+1);

}

}

...

}

The converView.getId() in the code above returns -1, despite the fact that the view id has already been assigned and is viewable during the code debugging. For example, I can see the following during debug:

converView= LinearLayout (id= 830042440680)

Any idea why I am getting -1 (= NO_ID) in the above code ?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值