删除一个项目从ListView中的自定义适配器内部 [英] Removing an item from ListView inside a custom adapter

查看:176
本文介绍了删除一个项目从ListView中的自定义适配器内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义列表视图项,其中包括删除按钮。我创建了一个名为自定义适配器 LazyListAdapter 扩展 BaseAdapter 。里面是我重写我设置这个按钮的onclick方法如下getView方法:

I have a custom listview item that includes a 'remove' button. I created a custom adapter called LazyListAdapter that extends BaseAdapter. Inside the getView method that I override I set this button's onclick method as follows:

@Override
public View getView(final int pos, View convertView, ViewGroup parent) {

     View v = convertView;

     // Some other things...

     ImageButton removeFav = (ImageButton) v.findViewById(R.id.removeFavorites);

     removeFav.setOnClickListener(new OnClickListener() {

     @Override
     public void onClick(View v) {

          // I delete the object from Parse database here,
          // Therefore I want the view to disappear here
     }
}

如何删除或以某种方式隐藏使用这种方法的onclick里面code中的相应看法?或者我应该改变我的做法?

How can I delete or somehow hide the corresponding view by using a code inside this onclick method? Or should I change my approach?

感谢你这么多提前。

推荐答案

试试这个

@Override
public View getView(final int pos, View convertView, ViewGroup parent) {

    View v = convertView;

    // Some other things...

    ImageButton removeFav = (ImageButton) v.findViewById(R.id.removeFavorites);

    removeFav.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

       // After you delete the object from Parse database here,
       notifyDataSetChanged();

    }
}

这篇关于删除一个项目从ListView中的自定义适配器内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆