With the following code I am able to successfully remove a View from a LinearLayout when clicking for a longtime on a button:
button.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
linearlayout.removeView(view);
return false;
}
});
And the activity it's updated instantly.
However when I try to achieve the same thing (removing that same View from the same LinearLayout) by the negative button of an AlertDialog, it only works when I close the app (basically when the activity is restarted). I don't know why it doesn't update the activity instantly.
Code:
.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.out.println("test");
ll.removeView(view);
//ll.invalidate();
//dialog.dismiss();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
//stuff
}
}, 1000);
}
});