在listview中直接显示的是数据库中的内容,如何实现新增以后listview中显示所有的数据包括新增???
1个回答
展开全部
你listview肯定写个adapter,如果自己重写adapter 写个setlist的方法,获取所有数据后直接setlist,然后在adapter里面的getview里面吧setlist里面的list赋值给view,然后在activity里面这个adapter.notifyDataSetChanged()
这是我原来重写的adapter
package com.liandisys.KohlerVab.activity.music;
import java.util.List;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.liandisys.KohlerVab.activity.R;
import com.liandisys.KohlerVab.bean.MusicContentBean;
/**
* 重写adapt
*
* **/
public class EditMusicListAdapt extends BaseAdapter {
private class GridHolder {
TextView appName;
}
private GridHolder holder;
private Context context;
private List<?> list;
private LayoutInflater mInflater;
private Typeface tf;
// 图片
// private int[] imgages = { R.drawable.menu_ting_on,
// R.drawable.menu_xin_on,
// R.drawable.menu_x_on, R.drawable.menu_wjj_on,
// R.drawable.menu_jia_on, R.drawable.menu_ban_on };
// 更新提示的图片
// private int[] imgages2 = { R.drawable.menu_ting_new_on,
// R.drawable.menu_xin_new_on, R.drawable.menu_x_new_on,
// R.drawable.menu_wjj_new_on, R.drawable.menu_jia_new_on,
// R.drawable.menu_ban_new_on };
public EditMusicListAdapt(Context c) {
this.context = c;
}
public EditMusicListAdapt(Context c , Typeface tf) {
this.context = c;
this.tf = tf;
}
public void setList(List<?> list) {
this.list = list;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return list.size();
}
@Override
public Object getItem(int index) {
return list.get(index);
}
//
@Override
public long getItemId(int index) {
return index;
}
@Override
public View getView(int index, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(R.layout.music_list_item, null);
holder = new GridHolder();
holder.appName = (TextView) convertView
.findViewById(R.music_list_item.textview);
if (list.get(index) instanceof MusicContentBean) {
MusicContentBean musicPlaylistBean = (MusicContentBean) list
.get(index);
holder.appName.setText(musicPlaylistBean.getMusic_name());
if(!musicPlaylistBean.isClick_flag()){
holder.appName.setBackgroundResource(R.drawable.music_song);
}else{
holder.appName.setBackgroundResource(R.drawable.music_song_hover);
}
holder.appName.setTextSize(13);
holder.appName.setTypeface(tf);
}
convertView.setTag(holder);
return convertView;
}
}
这是我原来重写的adapter
package com.liandisys.KohlerVab.activity.music;
import java.util.List;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.liandisys.KohlerVab.activity.R;
import com.liandisys.KohlerVab.bean.MusicContentBean;
/**
* 重写adapt
*
* **/
public class EditMusicListAdapt extends BaseAdapter {
private class GridHolder {
TextView appName;
}
private GridHolder holder;
private Context context;
private List<?> list;
private LayoutInflater mInflater;
private Typeface tf;
// 图片
// private int[] imgages = { R.drawable.menu_ting_on,
// R.drawable.menu_xin_on,
// R.drawable.menu_x_on, R.drawable.menu_wjj_on,
// R.drawable.menu_jia_on, R.drawable.menu_ban_on };
// 更新提示的图片
// private int[] imgages2 = { R.drawable.menu_ting_new_on,
// R.drawable.menu_xin_new_on, R.drawable.menu_x_new_on,
// R.drawable.menu_wjj_new_on, R.drawable.menu_jia_new_on,
// R.drawable.menu_ban_new_on };
public EditMusicListAdapt(Context c) {
this.context = c;
}
public EditMusicListAdapt(Context c , Typeface tf) {
this.context = c;
this.tf = tf;
}
public void setList(List<?> list) {
this.list = list;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return list.size();
}
@Override
public Object getItem(int index) {
return list.get(index);
}
//
@Override
public long getItemId(int index) {
return index;
}
@Override
public View getView(int index, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(R.layout.music_list_item, null);
holder = new GridHolder();
holder.appName = (TextView) convertView
.findViewById(R.music_list_item.textview);
if (list.get(index) instanceof MusicContentBean) {
MusicContentBean musicPlaylistBean = (MusicContentBean) list
.get(index);
holder.appName.setText(musicPlaylistBean.getMusic_name());
if(!musicPlaylistBean.isClick_flag()){
holder.appName.setBackgroundResource(R.drawable.music_song);
}else{
holder.appName.setBackgroundResource(R.drawable.music_song_hover);
}
holder.appName.setTextSize(13);
holder.appName.setTypeface(tf);
}
convertView.setTag(holder);
return convertView;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询