我有一个自定义列表视图项,其中包含一个“删除”按钮.我创建了一个名为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方法中的代码删除或以某种方式隐藏相应的视图?或者我应该改变我的做法?
非常感谢你提前.
解决方法
试试这个
@Override public View getView(final int pos,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(); } }