我在我的适配器上有一个稍微奇怪的错误。 适配器正在创建的视图是左侧的缩略图和有几行的表格。每行有两个文字浏览。convertView失去onitemClick listView滚动后
其中一个textview有android:autoLink="web"
属性集,而listview上有一个onItemClickListener。
问题是,每当TextView自动链接它的内容时,下次它的父视图被转换时,它不会再从onItemClickListener接收点击。
让我用一个例子阐明:
- 厂景,视图2,VIEW3和view4都在屏幕上的列表视图。
- view2有一个链接,它出现,onClick链接打开。
- 该项目点击正常工作view1,view3和view4。
- 滚动列表视图并将视图1转换为位置5,然后将视图2转换为位置6。
- 位置6上的项目不包含链接,但onItemClick也未触发position6元素。
textview的自动链接功能肯定会改变我的布局,但我不知道是什么。必须有一个属性,我可以重置每个调用getView在我的适配器上,但哪些?
感谢您的任何帮助。
编辑
让我们来看看一些代码,这是相当标准/良好做法。 从我的适配器getView是: @Override 公共视图getView(INT位置,查看convertView,父的ViewGroup){
// 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>
带有图像视图和表格以及几个边距的线性布局。
澄清问题的最佳方法是发布适当的代码。 – Sam
嗨。这是你的标准好习惯实现listview + adapter + loader。我现在编辑帖子。 – Budius
也显示'createNewView()',因为这是创建和设置视图的地方。 – Geobits