【发布时间】:2011-05-22 16:51:50
【问题描述】:
我正在开发一个使用 Listview Activity 的音板应用程序。但由于 Android 的 Listview 具有回收其列表视图的属性,我对所选文本视图所做的更改会在滚动列表视图时反映在所有页面中。我不希望这种情况发生。那么我该如何正确处理呢。如果有人可以帮助我编写代码 sn-p,那将非常有帮助,我感谢您的努力。谢谢!
编辑:希望这会更好地解释
我的类扩展了ListActivity,listview如下
[Image] [Text]
[Image] [Text]
[Image] [Text]
现在当用户点击任何文本视图时,我需要更改该文本视图的图像。我通过以下代码实现。
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
TextView tv = (TextView) view;
//Here I change the image with tv as reference
final Resources res = getBaseContext().getResources();
final Drawable myImage = res.getDrawable(R.drawable.pause);
// myImage.
final Drawable myImage1 = res.getDrawable(R.drawable.play);
tv.setCompoundDrawablesWithIntrinsicBounds(myImage, null, null, null);
MediaPlayer.OnCompletionListener listener = new MediaPlayer.OnCompletionListener(){
public void onCompletion(MediaPlayer mp) {
tv.setCompoundDrawablesWithIntrinsicBounds(myImage1, null, null, null);
}
};
}
【问题讨论】: