我在这里有我的适配器稍显怪异的错误。 适配器创建视图是在左侧的缩略图和表几排。每一行有两个textviews。
I'm having a slightly weird error here on my adapter. The view the adapter is creating is a thumbnail on the left side and a table with a few rows. Each row have two textviews.
其中textviews的有机器人:自动链接=网络
属性集和列表视图有一个onItemClickListener就可以了。
One of the textviews have the android:autoLink="web"
property set and the listview have an onItemClickListener on it.
问题是,每次一个TextView自动链接它的内容,下一次它的父视图转换,它不会从onItemClickListener获得点击了。
the problem is that every time a TextView auto-links it's content, next time its parent view is converted, it doesn't receive clicks from the onItemClickListener anymore.
让我澄清一个例子:
在厂景,视图2,VIEW3和view4都在屏幕上的列表视图。 视图2有一个链接,它的出现,和的onClick的链接打开。 的项目点击正常工作的厂景,观3和view4。 滚动ListView和厂景转化为POSITION5然后视图2转换为POSITION6。 在POSITION6该项目不包含一个链接,但onItemClick也没有解雇的POSITION6元素。TextView的的自动链接功能肯定是不断变化的东西与我的布局,但我不知道是什么。必须有一个属性,我可以重新在我的适配器每次调用getView,但它?
the autolink feature of the textview is certainly changing something with my layout, but I don't know what. There must a property I can reset for every call to getView on my adapter, but which?
感谢您的帮助。
修改
让我们看到一些code,这是pretty的标准/良好做法。 从我的适配器getView是: @覆盖 公共查看getView(INT位置,查看convertView,ViewGroup中父){
let's see some code, it's pretty standard/good practices. the getView from my adapter is: @Override 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的,并与一些余量东西表格布局水平线性布局,这里是该行布局:
that layouts used is a image and table and the amount of rows I inflate and insert on the table varies for each adapter. The table layout is a horizontal linear layout with a imageview and the table layout with some margin stuff and here is the row layout:
<?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>
如果我完全删除安卓自动链接=网络
我得到的所有点击,但如前所述,一旦视图获取自动连接,然后我回收这种观点,我不能让该视图上点击一次。
if I completely remove the android:autoLink="web"
I get all the clicks, but as stated before, once a view gets "auto-linked" and then I recycle that view, I can't get clicks on that view again.
修改
和这里的布局通胀的:
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布局:
and before someone else asks, that's the expandable_child_view layout:
<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的和一张桌子和一些利润率的线性布局。
as I said before, just a linear layout with a imageview and a table and a few margins.
据罗曼盖伊的此处,这是由设计完成的,支持轨迹球/ DPAD导航。 评论27 有一个解决方法是,通过设置后代可聚焦于每个ListView项:
According to Romain Guy here, this is done by design to support trackball/dpad navigation. Comment 27 has a workaround to it, by setting descendant focusability on each listview item:
setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
或
android:descendantFocusability="blocksDescendants"