自定义列表视图项仅在滚动之前加载默认值

时间:2016-02-09 15:24:54

标签: android listview android-arrayadapter

我使用了自定义列表视图,但大多数项目首先显示其默认值,直到我向下滚动,同时滚动部分项目数据,另一项显示默认值

示例:enter image description here

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

0 个答案:

没有答案