Bud*_*ius 3 android android-adapter android-adapterview
我的适配器上有一个有点奇怪的错误.适配器正在创建的视图是左侧的缩略图和带有几行的表.每行有两个textview.
其中一个textview具有android:autoLink="web"属性集,listview上有一个onItemClickListener.
问题是,每当TextView自动链接它的内容时,下次转换其父视图时,它就不再从onItemClickListener接收点击.
让我用一个例子来澄清:
textview的自动链接功能肯定会改变我的布局,但我不知道是什么.在我的适配器上每次调用getView时都必须重置一个属性,但是哪个?
谢谢你的帮助.
编辑
让我们看一些代码,这是非常标准/良好的做法.来自我的适配器的getView是:@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;
}
Run Code Online (Sandbox Code Playgroud)
使用的布局是图像和表格,我在表格中充气和插入的行数因每个适配器而异.表格布局是一个水平线性布局,带有一个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>
Run Code Online (Sandbox Code Playgroud)
如果我完全删除了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);
}
Run Code Online (Sandbox Code Playgroud)
在别人问之前,那就是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>
Run Code Online (Sandbox Code Playgroud)
正如我之前所说,只是一个带有imageview和一个表格以及一些边距的线性布局.
据罗曼盖伊这里,这是由设计做支持轨迹球/ DPAD导航.注释27有一个解决方法,通过在每个listview项上设置后代可聚焦性:
setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
Run Code Online (Sandbox Code Playgroud)
要么
android:descendantFocusability="blocksDescendants"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1849 次 |
| 最近记录: |