アダプターで少し奇妙なエラーが発生しています。アダプタが作成しているビューは、左側のサムネイルと数行のテーブルです。各行には2つのテキストビューがあります。
テキストビューの1つにはandroid:autoLink="web"
プロパティが設定されており、リストビューにはonItemClickListenerがあります。
問題は、TextViewがコンテンツを自動リンクするたびに、次にその親ビューが変換されるときに、onItemClickListenerからのクリックを受け取らないことです。
例を挙げて明確にしましょう。
- view1、view2、view3、view4は画面のリストビューにあります。
- view2にリンクがあり、それが表示され、onClickをクリックするとリンクが開きます。
- アイテムのクリックは、view1、view 3、view4で正常に機能します。
- リストビューをスクロールすると、view1がposition5に変換され、次にview2がposition6に変換されます。
- position6のアイテムにはリンクが含まれていませんが、position6要素に対してonItemClickも起動されません。
テキストビューの自動リンク機能は確かに私のレイアウトで何かを変えていますが、私は何を知りません。アダプタでgetViewを呼び出すたびにリセットできるプロパティが必要ですが、どれですか?
助けてくれてありがとう。
編集
いくつかのコードを見てみましょう、それはかなり標準的/良い習慣です。アダプターからのgetViewは次のとおりです。@Overridepublic 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>
前に言ったように、イメージビューとテーブルといくつかの余白がある線形レイアウトです。