我在我的適配器上有一個稍微奇怪的錯誤。 適配器正在創建的視圖是左側的縮略圖和有幾行的表格。每行有兩個文字瀏覽。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