我有一个Expandablelistview
,其中有一个按钮,用于删除数据库中提供listview
的项目。这些项目已被删除,但我需要离开活动并返回到该项目以查看该项目已消失。我想过只调用主要活动,但startActivity(intent)
用红色加下划线。我尝试了各种各样的。请有人帮忙。谢谢
@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup)
{
final String item = (String)this.getGroup(i);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.parent_layout, null);
}
final TextView itemTV = view.findViewById(R.id.parent_shopping_item);
itemTV.setText(item);
CheckBox checkBox = view.findViewById(R.id.checkBox);
Button deleteItemBtn = view.findViewById(R.id.button);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked)
{
itemTV.setPaintFlags(itemTV.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
if (! isChecked)
{
itemTV.setPaintFlags(itemTV.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
}
});
deleteItemBtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
DBManager dbManager = new DBManager(context, null, null, 1);
dbManager.deleteItem(item);
Intent intent = new Intent(context, MainActivity.class);
startActivity(intent);
}
});
return view;
}
答案 0 :(得分:0)
我想打电话
yourAdapter.notifyDataSetChanged();
而不是尝试再次调用您的活动,将更新您的listView。
答案 1 :(得分:0)
需要添加 onClick 方法:
@Override
public void onClick(View view)
{
DBManager dbManager = new DBManager(context, null, null, 1);
dbManager.deleteItem(item);
Intent intent = new Intent(context, MainActivity.class);
Bundle bundle = new Bundle();
startActivity(context, intent, bundle);
}