自定义item布局中一开始delete button是隐藏的 本人希望长按ListView中的item响应之后将Button显示出来,这是本人的adapter:
private class MyAdapter extends BaseAdapter { private LayoutInflater inflater; public MyAdapter(Context context) { this.inflater = LayoutInflater.from(context); } @Override public int getCount() { return (list.size()); } @Override public Object getItem(int position) { return(list.get(position)); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView==null) { convertView =inflater.inflate(R.layout.list_items_layout,null); holder=new ViewHolder(); holder.item_bt_delete=(Button)convertView.findViewById(R.id.list_items_bt_delete); holder.item_tv_date=(TextView)convertView.findViewById(R.id.list_items_date); holder.item_tv_detail=(TextView)convertView.findViewById(R.id.list_items_detail); holder.item_tv_dbnumber=(TextView)convertView.findViewById(R.id.list_items_dbnumber); holder.item_tv_number=(TextView)convertView.findViewById(R.id.list_items_number); convertView.setTag(holder); }else{ holder=(ViewHolder)convertView.getTag(); } //配置数据 holder.item_tv_detail.setText(list.get(position).get("detail").toString()); holder.item_tv_date.setText(list.get(position).get("date").toString()); holder.item_tv_dbnumber.setText(list.get(position).get("dbnumber").toString()); return convertView; } public final class ViewHolder{ public Button item_bt_delete; public TextView item_tv_detail; public TextView item_tv_date; public TextView item_tv_dbnumber; public TextView item_tv_number; } }
在MainActivity中,配置listView
adapter=new MyAdapter(this); listView.setAdapter(adapter); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { //********************************* return false; } });
求问*里面应该怎么写 才能去修改对应position位置上Button的visibility值?
解决方案
5
可以在适配器中定义一个int 的变量,然后再getview方法中通过判断参数position与该变量能否相同来进行你要的操作,而listview的item点击事件中只要把position传给adapter的int变量,然后adapter刷新一下就可以了
15
convertView.setOnLongClickListener()就可以了