我正在尝试使用按钮单击在我的 ListView 的每一行中显示和隐藏一个删除按钮。
为此,我尝试使用以下代码:
SavedHomeBaseAdapter extends BaseAdapter {
private LayoutInflater mInflater;
Context cntx;
public SavedHomeBaseAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return m_savedHomesList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressWarnings("deprecation")
@Override
public View getView( final int position, View convertView,final ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.nearbyhomestext, null);
holder = new ViewHolder();
holder.sqrt = (TextView) convertView.findViewById(R.id.text_squareft);
holder.fromPrice = (TextView) convertView.findViewById(R.id.text_from_price);
holder.deleteButton = (Button) convertView.findViewById(R.id.delete_btn);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
}
if(MyActivity.editButtonState)
{
holder.deleteButton.setVisibility(View.INVISIBLE);
notifyDataSetChanged();
MyActivity.editButtonState =false;
}
return convertView;
}
}
在这里,如果 editButtonState 为 true.. 则第一行的删除按钮被隐藏。但是,我想从列表视图中隐藏所有项目的删除按钮。
请帮我。提前致谢。