【发布时间】:2019-05-29 11:30:23
【问题描述】:
我想在长按该项目时删除一个列表视图项目。删除项目后,我需要重新启动活动以查看更改,但我想立即查看更改
我已经尝试过 notifyDataSetChanged();但它不起作用我从 sqlite 数据库中获取数据并将其放入 hashmaps 并将其发送到自定义适配器 长按时会从数据库中删除一行,但列表视图中不会发生任何更改。
@Override
public View getView( final int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
ImageView imageView = view.findViewById(R.id.detailsimage);
CardView cardView = view.findViewById(R.id.detailcardView);
TextView textmo =view.findViewById(R.id.detailsmo);
TextView texttu =view.findViewById(R.id.detailstu);
TextView textwe =view.findViewById(R.id.detailswe);
TextView textth =view.findViewById(R.id.detailsthu);
TextView textfr =view.findViewById(R.id.detailsfri);
TextView textsa =view.findViewById(R.id.detailssat);
TextView textsu =view.findViewById(R.id.detailssun);
final databasehandler db = new databasehandler(context);
cardView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
db.deleteTitle(position+1);
Toast.makeText(context,Integer.toString(position),Toast.LENGTH_SHORT).show();
notifyDataSetChanged();
return true;
}
});
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
HashMap<String, String> hashmap= arrayList.get(position);
String string= hashmap.get("repeat");
string = Objects.requireNonNull(string).trim();
Toast.makeText(context,string,Toast.LENGTH_SHORT).show();
}
});
HashMap<String, String> hashmap= arrayList.get(position);
String string= Objects.requireNonNull(hashmap.get("repeat")).trim();
String[] separated = Objects.requireNonNull(string).split("");
}
}}
return view;
}
}
【问题讨论】:
-
您必须从列表中删除该项目才能看到更改。
标签: android listview baseadapter