【发布时间】:2013-05-01 10:07:21
【问题描述】:
我有一个ListView。当我单击列表视图行的按钮时,将在main.xml 中创建一个按钮,我在自定义列表视图适配器中拥有该按钮的onclicklistener。我在 sqlite 中保存了对该按钮的单击,并通过该 sqlite 更新了 gridview 适配器。
所以我的问题是,当我单击按钮时,GridView 不会自行更新,当我关闭应用程序并再次打开它时,它会更新。
我尝试使用notifydatasetchanged(),但没有成功..
这是自定义列表视图适配器中的代码
holder.checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = holder.tvName.getText().toString();
String image = holder.tvimageurl.getText().toString();
DatabaseHandler db = new DatabaseHandler(activity);
db.addContact(new Contact(text, image));
db.close();
这在主活动中
GridView listView = (GridView) findViewById(R.id.gridview1);
imgAdapter = new ImageAdapter(this);
listView.setAdapter(imgAdapter);
imgAdapter.notifyDataSetChanged();
ImageAdapter 代码。
public class ImageAdapter extends BaseAdapter {
Activity activity;
List<Contact> item;
LayoutInflater inflater;
ImageAdapter imgAdapter;
private DisplayImageOptions options;
private DisplayImageOptions options2;
ImageLoader imageLoader;
private Contact objBean;
String getUrl,getId;
ObjectOutputStream oos;
FileOutputStream fos;
public ImageAdapter(Activity act) {
this.activity=act;
inflater = act.getLayoutInflater();
DatabaseHandler db = new DatabaseHandler(activity);
item = db.getAllContacts();
db.close();
}
@Override
public int getCount() {
return item.size();
}
@Override
public Contact getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final LinearLayout imageView;
if (convertView == null) {
imageView = (LinearLayout) inflater.inflate(R.layout.item_grid_image, parent, false);
} else {
imageView = (LinearLayout) convertView;
}
【问题讨论】:
标签: android listview button refresh