我使用了自定义列表视图,但大多数项目首先显示其默认值,直到我向下滚动,同时滚动部分项目数据,另一项显示默认值
Adatper代码:
flexbox
更新:包含private class MyAdapter extends ArrayAdapter<Song> {
public MyAdapter(Activity activity){
super(activity, R.layout.song_view, songs);
}
@Override
public Song getItem(int position) {
return super.getItem(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if(itemView == null) {
itemView = getActivity().getLayoutInflater().inflate(R.layout.song_view, parent, false);
}
Song currentSong = songs.get(position);
Toast.makeText(getContext(), currentSong.getName() +" " + position, Toast.LENGTH_SHORT).show();
ImageView imageView = (ImageView)view.findViewById(R.id.defalut_song_image);
try{
Bitmap songImage = BitmapFactory.decodeByteArray(currentSong.getImage(), 0, currentSong.getImage().length);
imageView.setImageBitmap(songImage);
}catch (Exception d){
}
try {
TextView songName = (TextView) view.findViewById(R.id.song_name);
songName.setText(currentSong.getName());
}catch (Exception e){
}
try {
TextView duration = (TextView)view.findViewById(R.id.duration);
long durationString = currentSong.getDuration();
long min = durationString / 60000;
long sec = (durationString % 60000) / 1000;
duration.setText(min + ":" + sec);
}catch (Exception e){
}
try {
TextView artist = (TextView)view.findViewById(R.id.artist);
artist.setText(currentSong.getArtist());
}catch (Exception e){
}
return itemView;
}
@Override
public int getCount() {
return songs == null ? 0 : songs.size();
}
}
Adapter