I have an Expandablelistview
with a button which deletes items from the database which feeds the listview
. The items are getting deleted, but I need to leave the activity and go back to it to see the item gone. I thought of just calling the main activity, but the startActivity(intent)
is underlined in red. I have tried all sorts. Please can someone help. Thank you
@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;
}
I think calling
yourAdapter.notifyDataSetChanged();
instead of trying to call your activity again, will update your listView.
Needed to add in the onClick method:
@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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.