android–convertView在滚动listView后丢失onitemClick

android–convertView在滚动listView后丢失onitemClick,第1张

概述我的适配器上有一个有点奇怪的错误.适配器正在创建的视图是左侧的缩略图和带有几行的表.每行有两个textview.其中一个textviews具有android:autoLink=“web”属性集,listview上有一个onItemClickListener.问题是,每当TextView自动链接它的内容时,下次转换其父视图时,它就不再从o

我的适配器上有一个有点奇怪的错误.
适配器正在创建的视图是左侧的缩略图和带有几行的表.每行有两个textvIEw.

其中一个textvIEws具有android:autolink =“web”属性集,ListvIEw上有一个onItemClickListener.

问题是,每当TextVIEw自动链接它的内容时,下次转换其父视图时,它就不再从onItemClickListener接收点击.

让我用一个例子来澄清:

> vIEw1,vIEw2,vIEw3和vIEw4位于屏幕上的列表视图中.
> vIEw2有一个链接,它出现了,点击该链接打开.
>项目点击对于vIEw1,vIEw 3和vIEw4正常工作.
>滚动列表视图,vIEw1转换为position5,然后vIEw2转换为position6.
> position6处的项目不包含链接,但也不会为position6元素触发onItemClick.

textvIEw的自动链接功能肯定会改变我的布局,但我不知道是什么.在我的适配器上每次调用getVIEw时都必须重置一个属性,但是哪个?

谢谢你的帮助.

编辑

让我们看一些代码,这是非常标准/良好的做法.
我的适配器的getVIEw是:
        @覆盖
        public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent){

    // Inflate a new layout if needed    if (convertVIEw == null)        convertVIEw = createNewVIEw();    // Gets the item from my array    AGplus item = (AGplus) getItem(position);    // Gets the holder pointing to the vIEws    Holder h = (Holder) convertVIEw.getTag();    // That's a test version, I won't be using date.toString() later on    h.date.setText(new Date(item.getDate()).toString());    // This guys is giving me a headache,    // If it parses the link, I can't never click on this convertVIEw anymore,    // event re-converting them for a text that does not contain links    h.txt.setText(item.getTitle());    // some image download stuff that doesn't matter for this code    return convertVIEw;    }

使用的布局是图像和表格,我在表格中充气和插入的行数因每个适配器而异.表格布局是一个水平线性布局,带有一个imagevIEw,表格布局带有一些边距,这里是行布局:

    <?xml version="1.0" enCoding="utf-8"?>    <tableRow xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content" >        <TextVIEw            androID:ID="@+ID/Title"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:textAppearance="?androID:attr/textAppearanceSmall"            androID:textcolor="@color/text" />        <TextVIEw            androID:ID="@+ID/text"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:autolink="web"            androID:text=""            androID:textAppearance="?androID:attr/textAppearanceSmall"            androID:textcolor="@color/text" />    </tableRow>

如果我完全删除androID:autolink =“web”我得到所有点击,但如前所述,一旦视图“自动链接”然后我回收该视图,我再也无法点击该视图.

编辑

这是布局膨胀:

    private VIEw createNewVIEw() {    // Instantiate vIEw    VIEw v = getLayoutInflater().inflate(R.layout.expandable_child_vIEw, null);    tableLayout table = (tableLayout) v.findVIEwByID(R.ID.table);    Holder h = new Holder();    v.setTag(h);    // Instantiate rows    h.thumb = (ImageVIEw) v.findVIEwByID(R.ID.img);    h.date = (TextVIEw) createNewRow(table, "Date: ");    h.txt = (TextVIEw) createNewRow(table, "Text: ");    return v;    }    private VIEw createNewRow(VIEwGroup group, String Title) {    VIEw row;    row = getLayoutInflater().inflate(R.layout.item_table_row, null);    ((TextVIEw) row.findVIEwByID(R.ID.Title)).setText(Title);    group.addVIEw(row);    return row.findVIEwByID(R.ID.text);    }

在别人问之前,那就是expandable_child_vIEw布局:

    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:ID="@+ID/frame"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:gravity="center_vertical" >        <ImageVIEw            androID:ID="@+ID/img"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_marginBottom="20dp"            androID:layout_marginleft="40dp"            androID:layout_marginRight="5dp"            androID:layout_margintop="20dp"            androID:src="@drawable/ic_launcher" />        <tableLayout            androID:ID="@+ID/table"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent" >        </tableLayout>    </linearLayout>

正如我之前所说,只是一个带有imagevIEw和一个表格以及一些边距的线性布局.

解决方法:

根据Romain Guy here的说法,这是通过设计来完成的,以支持轨迹球/ dpad导航. Comment 27有一个解决方法,通过在每个ListvIEw项上设置后代可聚焦性:

setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);

要么

androID:descendantFocusability="blocksDescendants"
总结

以上是内存溢出为你收集整理的android – convertView在滚动listView后丢失onitemClick全部内容,希望文章能够帮你解决android – convertView在滚动listView后丢失onitemClick所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1109976.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存