qq_34242806
qq_34242806
2017-03-03 11:07

android菜鸟求助:ListView点击删除按钮时,总是最后一个item被删除

  • android
  • list

如题,我的ListView的每个item都有一个删除按钮,但是每次点击按钮后都是删除了最后一个item。

   调试后position是正确的,索引是没有问题的,每次删除的都是正确的位置,而且每次item一删除就调用notifyDataSetChanged()去刷新,这个问题困扰好几天了…麻烦大神帮帮忙。

public View getView(final int position, View view, ViewGroup arg2) {
// TODO Auto-generated method stub
if(view == null){
view = inflater.inflate(R.layout.mission_item, null);
SharedPreferences shared_mission = getSharedPreferences("mission",
Activity.MODE_PRIVATE);

            mission_name = (TextView) view.findViewById(R.id.pro_name);
            mission_add = (TextView) view.findViewById(R.id.pro_add);
            mission_phone = (TextView) view.findViewById(R.id.pro_phone);

            mission_name.setText(shared_mission.getString("name", ""));
            mission_add.setText(shared_mission.getString("address", ""));
            mission_phone.setText(shared_mission.getString("phone", ""));
        }
        Button del = (Button) view.findViewById(R.id.del);
        del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                arr.remove(position);
                mission_adapter.notifyDataSetChanged();
            }
        });  //删除按钮    
        listview.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,final int arg2,
                                    long arg3) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, MissionInfo.class);
                startActivity(intent);
            }
        });
        return view;
    }
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答