Android 从自定义列表视图中删除项目

Android 从自定义列表视图中删除项目,android,listview,Android,Listview,我试图在单击按钮时删除自定义listview的项目,删除功能正常工作,但问题是当我单击按钮时,项目不会在重新加载时立即删除 @Override public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup) { // TODO Auto-generated method stub LayoutInflater inflator = activity.getLayoutInflat

我试图在单击按钮时删除自定义listview的项目,删除功能正常工作,但问题是当我单击按钮时,项目不会在重新加载时立即删除

@Override
public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup) {
    // TODO Auto-generated method stub

    LayoutInflater inflator = activity.getLayoutInflater();
    if (paramView == null) {
        view = new ViewHolder();
        paramView = inflator.inflate(R.layout.listview_row, null);

        view.header = (TextView) paramView.findViewById(R.id.tvHeader);
        view.from = (TextView) paramView.findViewById(R.id.tvfrom);
        view.to = (TextView) paramView.findViewById(R.id.tvto);
        view.value = (EditText) paramView.findViewById(R.id.etValue);
        view.imgViewFlag = (ImageView) paramView.findViewById(R.id.ibclose);
        view.result = (TextView) paramView.findViewById(R.id.tvResult);

        paramView.setTag(view);

    } else {
        view = (ViewHolder) paramView.getTag();
    }

    view.header.setText(Header.get(paramInt));
    view.from.setText(From.get(paramInt));
    view.to.setText(To.get(paramInt));
    view.value.setText(Value.get(paramInt));
    view.imgViewFlag.setImageResource(close.get(paramInt));
    view.value.setFocusableInTouchMode(false);
    view.value.setFocusable(false);
    view.imgViewFlag.setFocusableInTouchMode(false);
    view.imgViewFlag.setFocusable(false);
    view.imgViewFlag.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            int i=paramInt+1;
            File f1 = new File("/data/data/com.example.converter/shared_prefs/"+i+".xml");



            if(f1.exists()){
                f1.delete();
                 Header.remove(paramInt);
                 From.remove(paramInt);
                 close.remove(paramInt);
                 To.remove(paramInt);
                 Value.remove(paramInt);
            }
            else{
                for(int l = i;i<6;){
                    File f2 = new File("/data/data/com.example.converter/shared_prefs/"+l+".xml");
                    if(f2.exists()){
                        f2.delete();
                         Header.remove(paramInt);
                         From.remove(paramInt);
                         close.remove(paramInt);
                         To.remove(paramInt);
                         Value.remove(paramInt);
                        break;
                    }
                    else{
                        l++;
                    }
                }

            }

        }
    });

    return paramView;
@覆盖
公共视图getView(最终int参数、视图参数、视图组参数){
//TODO自动生成的方法存根
LayoutFlater充气器=活动。GetLayoutFlater();
if(paramView==null){
视图=新的ViewHolder();
paramView=充气机。充气(R.layout.listview_行,空);
view.header=(TextView)paramView.findViewById(R.id.tvHeader);
view.from=(TextView)paramView.findViewById(R.id.tvfrom);
view.to=(TextView)paramView.findViewById(R.id.tvto);
view.value=(EditText)paramView.findViewById(R.id.etValue);
view.imgViewFlag=(ImageView)paramView.findViewById(R.id.ibclose);
view.result=(TextView)paramView.findViewById(R.id.tvResult);
setTag(视图);
}否则{
view=(ViewHolder)paramView.getTag();
}
view.header.setText(header.get(paramInt));
view.from.setText(from.get(paramInt));
view.to.setText(to.get(paramInt));
view.value.setText(value.get(paramInt));
view.imgViewFlag.setImageResource(close.get(paramInt));
view.value.setFocusableInTouchMode(false);
view.value.setFocusable(false);
view.imgViewFlag.setFocusableInTouchMode(false);
view.imgViewFlag.setFocusable(false);
view.imgViewFlag.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
int i=参数int+1;
文件f1=新文件(“/data/data/com.example.converter/shared_prefs/”+i+“.xml”);
if(f1.exists()){
f1.删除();
Header.remove(参数);
From.remove(参数);
关闭。删除(参数);
删除(参数);
Value.remove(paramInt);
}
否则{

对于(int l=i;i我发布了从listview中删除项目的代码,该代码在我的代码中正常工作

你忘了打电话了,就这样

    @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();
            }
        }
    );
请看下面的答案

(一)

(二)

如果您仍然面临任何问题,请告诉我


谢谢

我发布了从listview中删除项目的代码,该代码在我的代码中运行正常

你忘了打电话了,就这样

    @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();
            }
        }
    );
请看下面的答案

(一)

(二)

如果您仍然面临任何问题,请告诉我


谢谢

更新listview后,您是否在适配器上调用了
notifyDataSetChanged()
?您是否调用了
notifyDataSetChanged()
在适配器上,更新listview后?brother我想从自定义列表适配器中删除行,我想在单击按钮时删除该项,该按钮是从自定义listview中删除的,给定的代码u仅适用于简单适配器,但我需要适用于自定义列表的代码adapter@Rohit有关自定义列表适配器,请参阅以下内容:de…brother,我没有任何适配器,那么我如何使用这个示例brother我想从自定义列表适配器中删除行,我想在单击按钮时删除该项,该按钮是从自定义列表视图中删除的,给定的代码u仅用于简单适配器,但我需要用于自定义列表的代码adapter@Rohit对于自定义列表适配器,、see下面的代码…兄弟,我没有任何适配器,那么我如何使用这个示例呢