gpt4 book ai didi

java - 删除 CustomArrayAdapter 内 ListView 上的项目

转载 作者:行者123 更新时间:2023-12-01 13:19:44 24 4
gpt4 key购买 nike

我的listview的每个项目都有一个图像按钮,如果您单击该按钮,我想删除与当前图像按钮关联或当前聚焦的项目。

listview = (QuickReturnListView) v.findViewById(R.id.carddemo_list_expand);

String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
"OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
"Android", "iPhone", "WindowsMobile" };


list = new ArrayList<String>();
for (int i = 0; i < values.length; ++i) {
list.add(values[i]);
}

adapter = new MySimpleArrayAdapter(getActivity(), list);
listview.setAdapter(adapter);
<小时/>
 public class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> values;

public MySimpleArrayAdapter(Context context, ArrayList<String> list) {
super(context, R.layout.inner_base_header_cutom, list);
this.context = context;
this.values = list;
}

@Override
public View getView(final int position, View convertView, final ViewGroup parent) {

v.remove = (ImageView)rowView.findViewById(R.id.cancel);
v.remove.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub


//Global Variables
list.remove(position);
adapter.notifyDataSetChanged();


//

}
});

}

最佳答案

ArrayAdapter 具有 remove(T object) 方法,您应该调用该方法来清理您提供给父类(super class)的数据集:您应该在 onClick 内部调用

remove(list.get(position));

关于java - 删除 CustomArrayAdapter 内 ListView 上的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22143712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com