All*_*son 5 java android android-widget android-gallery android-adapter
我有一个扩展的 BaseAdapter,它的 LinearLayout 子项(每个子项中有一个 ImageView 和一个 TextView)连接到自定义图库。
当我第一次启动我的活动时,我想调用setSelection(position)使 ImageView 将其选择器更改为“选定”图像。一旦我在随后选定的孩子上扔画廊,这就会起作用,但不是第一次启动应用程序。
我的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/home_image_select" />
<item android:state_selected="false"
android:drawable="@drawable/home_image" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我的第一个猜测是在调用 setSelection() 之后在适配器上调用 notifyDataSetChanged(),我尝试这样做:
((CustomAdapter) gallery.getAdapter()).notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)
那没有任何作用。我还尝试覆盖 Gallery 类的 setSelection() 来执行此操作:
View v = this.getAdapter().getView(position, null, this);
((ImageView) v.findViewById(R.id.gallery_image)).setSelected(true);
Run Code Online (Sandbox Code Playgroud)
那也行不通。有什么我想念的或可以尝试的吗?
| 归档时间: |
|
| 查看次数: |
1568 次 |
| 最近记录: |