android 实时添加图片和文字到listview,如何实现?
2个回答
展开全部
在activity里面调用addOne就可以了。
图片和文字的显示需要自己写layiout文件R.layout.music_playlist_item
public class MusicPlayListAdapter extends BaseAdapter {
List<? extends PlayListInfo> data;
public MusicPlayListAdapter(List<? extends PlayListInfo> data) {
this.data = data;
}
public void addOne(PlayListInfo music) {
data.add(music);
notifyDataSetChanged();
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.music_playlist_item, null);
}
PlayListInfo music = data.get(position);
........
return convertView;
}
}
图片和文字的显示需要自己写layiout文件R.layout.music_playlist_item
public class MusicPlayListAdapter extends BaseAdapter {
List<? extends PlayListInfo> data;
public MusicPlayListAdapter(List<? extends PlayListInfo> data) {
this.data = data;
}
public void addOne(PlayListInfo music) {
data.add(music);
notifyDataSetChanged();
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.music_playlist_item, null);
}
PlayListInfo music = data.get(position);
........
return convertView;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询