public View getView(int arg0, View arg1, ViewGroup arg2) {
if(arg1==null){
arg1=layoutInflater.inflate(R.layout.items, null);
}
ImageView musicflag = (ImageView) arg1.findViewById(R.id.musicflag);
TextView musicname=(TextView) arg1.findViewById(R.id.musicname);
TextView musicsinger=(TextView) arg1.findViewById(R.id.musicsingers);
final ImageView musicplay = (ImageView) arg1.findViewById(R.id.musicatt);
musicflag.setImageResource(R.drawable.music);
musicname.setText(musics[arg0]);
musicsinger.setText(musicsingers[arg0]);
musicplay.setImageResource(R.drawable.play);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//Toast.makeText(MainActivity.this, arg2+"", Toast.LENGTH_SHORT).show();
/*if (flag==0) {
musicplay.setImageResource(R.drawable.pause);
flag=1;
}else if (flag==1) {
musicplay.setImageResource(R.drawable.play);
flag=0;
}*/
**musicplay.setImageResource(R.drawable.pause);_**
Toast.makeText(MainActivity.this, flag+"", Toast.LENGTH_SHORT).show();
Intent intent = new Intent("MusicPlay");
Bundle bundle = new Bundle();
bundle.putInt("song", arg2);
intent.putExtra("int", bundle);
sendBroadcast(intent);
}
});
為什麼musicplay.setImageResource(R.drawable.pause);這句話不能執行,圖片沒有更改
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
ImageView musicplay = (ImageView) arg1.findViewById(R.id.musicatt);//這裡重新獲取當前點擊的item對應的musicplay,不然musicplay是指向最後一個item的。
//Toast.makeText(MainActivity.this, arg2+"", Toast.LENGTH_SHORT).show();
/*if (flag==0) {
musicplay.setImageResource(R.drawable.pause);