大佬教程收集整理的这篇文章主要介绍了android:如何使用行中的删除按钮从ListView中删除行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用自定义行使用自定义cursorAdapter填充ListView.我有两个ListView状态:第一个状态只包含行中的文本;第二个状态在每一行都有一个删除按钮.两种状态之间的切换是视图底部的按钮.
我试图实现的是:在第一个状态,当我点击该行时,屏幕应切换到另一个视图.在第二种状态下,当我点击删除按钮时,应该从数据库中删除所选行,应该重新填充ListView,如果我按下除删除按钮以外的行的任何其他部分,则不会发生任何事情.
我知道如何删除一个项目,然后重新填充ListView,当我点击第一个状态的行时,我知道如何切换到另一个视图;但我无法将两者结合起来.我使用以下方法来获取行的id和位置:
protected void onListItemClick(ListView l,View v,int position,long id) { super.onListItemClick(l,v,position,id); //Code goes in here either for deleting or switching into another view }
我尝试使用一些if语句来获取单击删除按钮的条件或单击行但它不起作用.
第一个问题很明显:我怎样才能使它发挥作用?
第二个问题是:在第二个状态下按下行的任何部分而不是删除按钮屏幕切换到另一个视图.我怎么能阻止这个?我试图将行的.setClickable,.setPressed,.setSELEcted属性设置为false,但它没有帮助.
感谢您提前回复.
@Override public View getView(int position,View convertView,ViewGroup parent) { View row = null; LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.one_result_details_row,parent,falsE); // inflate other items here : Button deleteButton = (Button) row.findViewById(R.id.Details_Button01); deleteButton.setTag(position); deleteButton.setOnClickListener( new Button.onClickListener() { @Override public void onClick(View v) { Integer index = (Integer) view.getTag(); items.remove(index.intValue()); notifyDataSetChanged(); } } );
在getView()方法中,将ListItem标记为postion
deleteButton.setTag(position);
将getTag()对象转换为Integer
在OnClickListener()中,然后删除该项
items.remove(index.intValue());
以上是大佬教程为你收集整理的android:如何使用行中的删除按钮从ListView中删除行全部内容,希望文章能够帮你解决android:如何使用行中的删除按钮从ListView中删除行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。