我有一个自定义的listview项,其中包括一个“删除”按钮。我创建了一个自定义适配器LazyListAdapter
,它扩展了BaseAdapter
。在我覆盖的getView方法中,按如下所示设置此按钮的onclick方法:
@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方法中的代码删除或以某种方式隐藏相应的 View ?还是应该改变我的方法?
提前非常感谢您。
最佳答案
试试这个
@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();
}
}